Jump to content

Randomly Rename Files When Uploaded?


scheols

Recommended Posts

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

[code]<?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");
}
?>[/code]

so how can i rename the file when its uploaded 2 the servers.
Link to comment
https://forums.phpfreaks.com/topic/14659-randomly-rename-files-when-uploaded/
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.