Forum Moderators: coopster

Message Too Old, No Replies

PHP uploading files

         

dc_duo

5:39 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



Hi thanks for everyones help so far really apreciated. One more thing. I am currently allwong file uploads to my website however I want to be able to rename my files when they are uploaded this is my script for uploading which works fine.

if (is_uploaded_file($_FILES['image']['tmp_name'])){

if (move_uploaded_file($_FILES['image']['tmp_name'], "../uploads/{$_FILES['image']['name']}")) {

$problem = FALSE;

echo '<p align="center"><font color="red"><b>The file was uploaded</b></font></p>';

} else {

$problem = TRUE;

echo '<p>The file could not be moved because </p>';

$img_name = 'noimage.jpg' ;

}

$img_name = $_FILES['image']['name'];

} else {

$img_name = 'noimage.jpg';

}

What I would like to know is how I rename a file so it uploads as a different name (security reasons and to stop the scenario of 2 duplicate file names)

Hope someone can help

Steve C

mincklerstraat

6:06 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



change:

if (move_uploaded_file($_FILES['image']['tmp_name'], "../uploads/{$_FILES['image']['name']}")) {

to:

if (move_uploaded_file($_FILES['image']['tmp_name'], "../uploads/".$newname)) {

after setting $newname to the desired name, of course.

And read: [be2.php.net...]

Normally, you could answer your own question here by reading the manual on move_uploaded_file(), and fortunately I'm not in a carniverous mood today.