Jump to content


Photo

Randomly Rename Files When Uploaded?


  • Please log in to reply
2 replies to this topic

#1 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 15 July 2006 - 07:55 AM

When i used this it randomized the name but it doesnt randomize the file name so it tells the url thats the file doesnt exist

<?php
$maxfilesize = "524288";
if($_FILES['userfile']['size'] > $maxfilesize){
echo "File Size To Big Sorry Pick a Smaller File Size current is".$_FILES['userfile']['size']."0.5 megabyte Allowed Only or 512 kilobyte";
exit();
}
$dir = "images/";
if(file_exists($dir.$_FILES['userfile']['name'])){
die("Theirs a file already named after that");
exit();
}
$file_type = array("application/x-javascript","image/gif","image/pjpeg","text/plain","image/png","image/jpeg","image/bmp");
$name = substr(md5(mt_rand()), 5, 10) . substr($_FILES['thefile']['name'], -4);
if(in_array($_FILES['userfile']['type'],$file_type)){
if(!(copy($_FILES['userfile']['tmp_name'], "images/" . $_FILES['userfile']['name']))) die("Cannot upload files.");
echo "Upload Complete!<br>";
echo "<a href='"."http://xizionz.vectoredhost.com/images/"."$name"."'>"."Here"."</a>";
}else{
die("Sorry We Dont Execpt that file type");
}
?>

so how can i rename the file when its uploaded 2 the servers.
Dont Piss me Off today

#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 15 July 2006 - 07:59 AM

$name = substr(md5(mt_rand()), 5, 10) . substr($_FILES['thefile']['name'], -4);

try changing 'thefile' to 'userfile'

#3 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 15 July 2006 - 08:16 AM

yeah that parts fixed now i need help changing the file name thats on my server.

it went from :/613409f773 to /613409f773.txt

but that pade is still an error when i upload. i need the actuall file name changed.
Dont Piss me Off today




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users