• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Upload component then rename uploaded file

#1
I am stumped, some legacy code that I am updating works fine on an existing server but on 2 new servers it doesn't do what it is supposed to.

So standard file upload library used, file uploads fine. The customer wants to be able to name the file, so a field is provided on the upload form. Flow is as follows:
1) file uploaded
2) file name from the form is processed to remove any characters that would cause issues when used as a file name e.g. / or \ characters etc.
3) $filedata['file_ext'] appended to requested file name
4) Check if the requested file name is currently in use, if so create unique name using requested file name
5) Do rename using rename($config['upload_path'].$uploadfilename, $config['upload_path'].$renamedfile);
6) Insert relevant data into a database table along with renamed file name


Here's the odd thing, when run on the new server, the rename APPEARS to work, if (rename()) { echo "Success" } for instance, no errors in logs, but the file has disappeared. If I stop the process short of the rename, the file is definitely uploaded correctly. I tried copy, and then unlink as well, same result.

Debugging revealed that if I hard code a 'new file name' e.g. rename($config['upload_path'].$uploadfilename, './uploads/TestFile.pdf'); it will perform the rename correctly, however, if I set the file name on the input form to 'TestFile.pdf' it will not work.

So if the file name passed through from the form is the same as the file name that I want to rename to, it doesn't work. In fact if I reference the $filedata['file_name'] again, the rename doesn't work.

What am I missing ? This is driving me nuts.

Any help very gratefully received.
Reply

#2
@osfan,

Some questions...I hate to assume.
Do the two new servers have the same OS (as the old one)? PHP version? Security (folder) settings? Did it send any errors to the error log when it was unsuccessful in renaming the file?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.