This topic is locked

Delete upload files

10/5/2010 7:00:11 PM
PHPRunner General questions
S
sotosp author

When i upload a file through a record and then i want to edit the record, for the file field i think, i get 3 options. I would like to ask how to tell phprunner to delete the file when i choose to change to file ( upload a new one) or to empty the file field.

In my project i can delete the file only if i delete the record.
Is this the normal behavior? Because with this i get a lot of unwanted files on Server
Thnaks for your help

Sergey Kornilov admin 10/6/2010

Yes, this is the default behaviour, old files are not deleted when you upload a new one while editing the record.
You can delete old file using BeforeEdit event. In this event you have access to old file name.

S
sotosp author 10/6/2010

I need to ask you one more thing. Can you tell me the code that i need to write in order to perform this action?
Thank you in advance for your help

A
ann 10/6/2010

Hi,
hese is a sample code:

if ($values["FieldName"]!=$oldvalues["FieldName"] && $oldvalues["FieldName"])

if(file_exists("Files/".$oldvalues["FieldName"]))

@unlink("Files/".$oldvalues["FieldName"]);
return true;



where FieldName is your actual field name, Files is your actual directory where your files are stored.