RobertSubnet Posted October 13, 2007 Share Posted October 13, 2007 Hello all. Hopefully this is an easy question. I am having a problem with rename(). I have successfully uploaded a jpg to an upload directory on my web server-IIS. After the upload, I want to change the name of the uploaded file. The name change goes like this: timestamp + p1 + uploaded_filename.jpg I am trying to use rename() to rename the jpg file allready on the web server. PHP keeps putting out the following error: PHP Warning: rename() expects parameter 3 to be resource, string given in C:\Inetpub\wwwroot\kaydoo\upload.php on line 38 What sort of "resource" is PHP looking for? I am using PHP v.5.2.3 Any help would be much appreciated. Thanks, ~Robert The code and output is below: <?php //beta kaydoo picture uploader $p1 = 'p1'; $name = $_FILES['uploaded']['name']; $time = time(); $newname = $time.$p1.$name; //These two lines set the upload directory location, don't delete either line $target = "upload/"; $target = $target.basename($_FILES['uploaded']['name']); if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ".basename($_FILES['uploaded']['name']). " has been uploaded to the Kaydoo server"; }else{ echo "File upload, she no work man"; } echo "<br>"; echo "<br>"; echo "The original name of the uploaded file is $name"; echo "<br>"; echo "<br>"; echo "The renamed file is $newname"; echo "<br>"; echo "<br>"; $directory = "upload/"; rename($name, $newname, $directory); ?> ----------------- Script output: The file picacho.jpg has been uploaded to the Kaydoo server The original name of the uploaded file is picacho.jpg The renamed file is 1192259718p1picacho.jpg PHP Warning: rename() expects parameter 3 to be resource, string given in C:\Inetpub\wwwroot\kaydoo\upload.php on line 38 Quote Link to comment https://forums.phpfreaks.com/topic/73064-rename-help/ Share on other sites More sharing options...
derwert Posted October 21, 2007 Share Posted October 21, 2007 The 3rd parameter is to be used for context options when using streams; it's not for a directory. Quote Link to comment https://forums.phpfreaks.com/topic/73064-rename-help/#findComment-374626 Share on other sites More sharing options...
JJohnsenDK Posted October 21, 2007 Share Posted October 21, 2007 you need to point out where the file is located in the first parameter: $name = "images\$myfile"; dont use the 3. parameter. Quote Link to comment https://forums.phpfreaks.com/topic/73064-rename-help/#findComment-374630 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.