Rename uploaded file

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
Niall
Forum Newbie
Posts: 2
Joined: Wed Nov 04, 2009 3:43 pm
Location: Scotchland

Rename uploaded file

Post by Niall »

Hola! I'm fairly new to this whole PHP business, and I'm creating a file uploader for some experience / giggles.

So far I've got it working pretty well, however I'm wondering about how to rename the file once uploaded.
As for generating, I've gone pretty basic and just done current time + random number between 1 and 100. Simple enough.

What I'm doing is once the file is succesfully uploaded, renameUpload(); then move_uploaded_file etc.
This is the function in all it's glory:

Code: Select all

function renameUpload($file) {
    $rand = mt_rand(100, 999);
    $time = time();
    $ext = strstr($file,'.');
    $filenew = $rand.$time.$ext;
    rename($file, $filenew);
}
And once the upload is successful:

Code: Select all

else {
        renameUpload($name);
        move_uploaded_file($temp,"files/".$name);
        echo $success;
    }
$success is basically a string saying it uploaded successfully.

The problem is, when I run it I get this error:

Warning: rename(clark!.fla,1941257376894.fla) [function.rename]: No such file or directory in C:\xampp\htdocs\swfshire\upload.php on line 46

I'm not quite sure why.
Any suggestions? I'm pretty lost here, and most likely missing a trick.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Rename uploaded file

Post by Eric! »

Does "clark!.fla" exist in C:\xampp\htdocs\swfshire\? My guess is it doesn't.
Niall
Forum Newbie
Posts: 2
Joined: Wed Nov 04, 2009 3:43 pm
Location: Scotchland

Re: Rename uploaded file

Post by Niall »

Oh, WHOOPS HAHA


Thanks for pointing that out, dunno how I missed that. I've got it working now.
Post Reply