Jump to content

Image upload and Rename Help!


anthonydamasco

Recommended Posts

Want do you mean by ID?  Where is this ID you speak of?  Is it a primary key in a mysql table?

 

Anyways a quick google yeilds plenty of plausible solutions.  Here are just a few:

 

http://www.phpeasystep.com/workshopview.php?id=18

 

http://www.phpfreaks.com/quickcode/Rename-Files/549.php

 

or better yet try php.net and you will find the rename() function:

 

http://us2.php.net/manual/en/function.rename.php

my fully working example.

 

<?php session_start();

// if the id is set in a link use get or just leave it if the id
//is in a session.

$id=($_GET['id']);

// directory path.

$uploaddir = 'upload_new/';

// get the dir to send file to and the file name.

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

// get the current file information.
$file=$uploadfile;

//get the . and file exstention.
$ext = substr($file, -4);

//convert varable to the uplaoded directory the new id
//and extention.

$uploadfile=$uploaddir.$id.$ext;

//rename the file to the new one.

@rename($file,$uplaodfile);

// if all the conditions are correct send the file to the directory.

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){

// success echoed

echo " <font color='red'>File is valid, and was successfully uploaded.</font>";

}else {

//unsuccesfull echoed

echo "<font color='red'>File was unsuccesful sorry</font>";

}

// show the form.
   
echo"
<form enctype='multipart/form-data' action='new_test.php' method='POST'>
   
<input type='hidden' name='MAX_FILE_SIZE' value='30000000000000000000000'>

send this file <input name='userfile' type='file' >
    
<input type='submit' name='submit' value='Send File'>

</form>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.