Jump to content

renaming/uploading


supanoob

Recommended Posts

i have the following code to upload and rename a file. i want to change a couple of things

 

1) i want it to check make sure the file is gif/jpeg/jpg

2) i want it to put the file type back on the end. at the moment the url looks like this:

 

http://tordonline.p.sitesquat.com/profile/01

 

could someone advise on how to do both those things

 

<?php

if ($_GET['step'] == 'upload_new_complete')
                      {
                      // Your file name you are uploading
$file_name = $HTTP_POST_FILES['ufile']['name'];

// random 4 digit to add to our file name
// some people use date and time in stead of random digit

//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables

$new_file_name=$images_had.$account_id;

//set where you want to store files
//in this example we keep file in folder upload
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "/home/porky/public_html/profile/".$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";

//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file

$profile_image=($new_file_name.$HTTP_POST_FILES['type']);

$sql2="UPDATE tord_accounts SET profile_image='$profile_image' WHERE account_id='$account_id'";
                       if(mysql_query($sql2));


echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
echo "<a href=\"/profile/$new_file_name\">Click Here to View</a><br>";
echo "Image Thumbnail:<br>
<img src=\"/profile/$new_file_name\" width=\"150\" height=\"150\">";
}
else
{
echo "Error";
}
}
                      }

?>

Link to comment
https://forums.phpfreaks.com/topic/40587-renaminguploading/
Share on other sites

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.