I need to make any files uploaded to the web site to be converted to a random name.
I know how to do part of this:
Code: Select all
$photo=$_POST['photo'];
srand(time());
$random = (rand()%99999999);
$_FILES['photo']['$random'];
$newname="$random"."$photo";
if($filename !="")
{
copy ("$file", "images/productphotos/$newname")
or die ("could not copy file");
}
//This gets all the other information from the form
include "dbconn.php";
mysql_query("INSERT INTO vehicles
(userid, make, title, description, video, price, photoprimary) VALUES
('$userid', '$make', '$title', '$description', '$video', '$price', '$newname')");
It will generate the 'numbers' but all I get is either 234234 or 2342424_ if I stick an underscore in there too.
I also tried this method which is the original I found:
Code: Select all
// Generate Random Number
srand(time());
$random = (rand()%99999999);
// Add Random Number to First of File Name
$newName="$random"."_"."$file_name";
// Copy to Fold Append New File Name
if($file_name !="")
{
copy ("$file", "images_upload/$newName")
or die ("could not copy file");
}
else { die(); }All I need is how to get the filename, and I think I'm there.
Thanks
Simon