This topic is locked

Error when deleting a record containing Document Download field

9/5/2006 6:42:30 AM
PHPRunner General questions
A
andyjames author

Hi
This error occurs on a 3.0 project.

I have a table for users to upload their files. The table is a detail table to the user master table.

Each record has one field "filename" defined as Document Download/Document Upload field plus a few text fields qualifying the file.

The Folder where the file resides is defined as below the phprunner directory at "../lingfilesup" (I have tested it as a folder in the phprunner directory and the error still occurs).
If having created a record and uploaded a file, you then edit the record and for the filename field select "Delete..." from "Keep", "Delete..." "Update" to delete the file (but not the record), Save the changes thereby deleting the file from the server, then the record is listed with a blank field for the filename.

Fine everything working so far...

However, if you then select that RECORD for deletion in the _list.php page a PHP error occurs:

Technical information

Error type 2

Error description unlink(lingfilesup/) [function.unlink]: Is a directory

URL a-o.co.uk/phprunner/linguists/ling_files_up_list.php?

Error file /homepages/3/d22482688/htdocs/ao/phprunner/linguists/include/ling_files_up_functions.php

Error line 1718

SQL query delete from `ling_files_up` where (`files_id`=294) and (`ling_files_up`.`userid`=920)


This error ALWAYS occurs. I am aware that in the _list.php files, when deleting only owned records it checks to delete associated uploaded files if any.
The php error points to the "@unlink(GetUploadFolder($field).$value);" line in the following block of code in ling_files_up_functions.php:

function DeleteUploadedFiles($where)

{

global $conn,$strOriginalTableName;

$rs = db_query("select * from ".AddTableWrappers($strOriginalTableName)." where ".$where,$conn);

if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

{

if(GetEditFormat($field)==EDIT_FORMAT_FILE)

@unlink(GetUploadFolder($field).$value);

}

}

}


Is this something I am doing wrong or is it a bug? Any help would be appreciated.

Many thanks in advance.

J
Jane 9/5/2006

Andy,
it seems that you check off Delete file when associated record is deleted option on the Edit format dialog on the Formatting tab and then try to delete record without file.

You need to uncheck this option or delete record with associated file only.

A
andyjames author 9/5/2006

Hi Jane
Thanks for your reply. Yes if you disable the Delete file when associated record is deleted option on the Edit format dialog on the Formatting tab, then that stops the php error, however it doesn't solve the problem (sorry!)

At present if you enable the global option, it is possible for this error to happen <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10893&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
What I want to achieve is the following:

Keep the global Delete file when associated record is deleted option enabled and allow:

  1. users to delete the file on the edit.php page, keep other field data for this record and then subsequently delete the record without the file without causing the error.
  2. users to delete the record on the list.php page, and delete the associated file.
    One (unsatisfactory) workaround would be to remove the Delete file option on the edit.php page if the global Delete file when associated record is deleted option is enabled (thereby forcing the user to delete the whole record and not just the file if they want to delete that file).
    Is there any way of achieving the desired behaviour without causing the error?

    Thanks in advance for your support...

J
Jane 9/5/2006

Andy,
thank you for pointing to this issue.

We'll fix it in one of the next PHPRunner 3.1 update.

A
andyjames author 10/18/2006

Hi
I have figured out a fix for the aforementioned bug.

This is applies to version 3.0.

  1. Go to Miscellaneous Page in PHPRunner (Step 10 of 12)
  2. Click the Template Editor button and open your template
  3. Expand the Include subdirectory in the folder tree
  4. Open functions.php
  5. Search for this code block:

function DeleteUploadedFiles($where)

{

global $conn,$strOriginalTableName;

$rs = db_query("select * from ".AddTableWrappers($strOriginalTableName)." where ".$where,$conn);

if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

{

if(GetEditFormat($field)==EDIT_FORMAT_FILE)

@unlink(GetUploadFolder($field).$value);

}

}

}


6) and replace with this code:

function DeleteUploadedFiles($where)

{

global $conn,$strOriginalTableName;

$rs = db_query("select * from ".AddTableWrappers($strOriginalTableName)." where ".$where,$conn);

if($data=db_fetch_array($rs))

{

foreach($data as $field=>$value)

{

if((GetEditFormat($field)==EDIT_FORMAT_FILE) && (!($value=="null" || $value=="Null" || $value=="")))

{

@unlink(GetUploadFolder($field).$value);

}

}

}

}


7) Save the template file and rebuild your project.
Now when you delete a record containing an empty document upload field, it won't produce an error but it will delete the associated file if it is populated.
Not sure if this has been fixed in 3.1...

J
Jane 10/19/2006

Andy,
this issue was fixed in the PHPRunner 3.1.