Jump to content

rename() help


RobertSubnet

Recommended Posts

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

 

 

 

 

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.