yourguide
Posts: 44
|
Posted: 11/07/2013, 10:19 AM |
|
I am attempting to get the fileupload component to use the original name of the file on upload. I have searched the forums and find lots of discussion regarding why I shouldn't change the name to a non-unique name... but thats what I want to do for my purposes. I don't want to modify the classes.php either.
The documentation states on "File Upload Component Reference"
Before Process File -
This event occurs after an uploaded file is saved to the temporary directory but before it is moved to the target folder. This event can be used to check additional conditions or to change the file location or name.
But if I rename the file there by adding this:
$Component->SetValue($Component->GetFileName());
to the "Before Process File" event I get an error message saying it can't find the file any longer.
like this:
The file Helen Deering.jpg specified in FileUpload1 was not found.
The file temp/Helen Deering.jpg specified in FileUpload1 was not found.
So what am I to do? I don't want to edit the classes.php there must be a way to do this without modify CCS files directly.
Any help is appreciated.
Thanks.
_________________
Independent, self-employed, web developer. |
|
|
yourguide
Posts: 44
|
Posted: 11/07/2013, 12:16 PM |
|
Figured it out... it seems that its best to change the name in the AfterProcessFile event instead.
So here is my code in the "After Process File" event FYI :
$old=$Component->GetValue();
$new=$Component->GetFileName();
rename("files/".$old,"files/".$new);
I should note that I changed the "File Folder" property of the fileupload object to "files" that's why I have the folder listed in the rename statement above.
Hope this helps someone in the future. Possibly even myself. :)
_________________
Independent, self-employed, web developer. |
|
|
|