Re: Rename generates level 2 warning but works

From: Date: Wed, 31 Dec 2003 18:19:52 +0000
Subject: Re: Rename generates level 2 warning but works
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-173568@lists.php.net to get a copy of this message
> Lowell Allen wrote: > >> >> Try using $HTTP_POST_FILES['uploadedFile']['name'] instead. I wasted a >> bunch >> of time yesterday with an upload script that did not recognize files when >> using "$_FILES", but worked fine with "$HTTP_POST_FILES" -- PHP 4.3.4 >> on >> Linux. >> > Thank you for the suggestion. Unfortunately, it didn't resolve the > issue. Still getting the warning AND the rename function works. Odd > indeed... > > Thanks, > Roger > OK, well how about this -- you said your code is: $rename = time(); $old_name = $_FILES['uploadedFile']['name']; $read_extension = explode(".", $old_name); $ext = $read_extension[1]; $new_name = $rename.".".$ext; rename($old_name, $new_name); And your error message is "rename() failed (No such file or directory)", but isn't $_FILES['uploadedFile']['name'] the original file name before uploading, whereas $_FILES['uploadedFile']['tmp_name'] is where the file was uploaded to on the server. So the first is just a name, and the second is the file location. Also, you're defining what $new_name is before you even use rename(), so even if rename() fails, you've set the desired value for $new_name. But what you have not done is actually move the uploaded file. If it's being uploaded to /tmp, it will be deleted when your script ends. So, I think you need to pass rename parameters that are file locations. HTH -- Lowell Allen

« previous php.general (#173568) next »