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

Link to comment
Share on other sites

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>";

?>

Link to comment
Share on other sites

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.