Jump to content

Archived

This topic is now archived and is closed to further replies.

scheols

Randomly Rename Files When Uploaded?

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.

Share this post


Link to post
Share on other sites
$name = substr(md5(mt_rand()), 5, 10) . substr($_FILES['thefile']['name'], -4);

try changing 'thefile' to 'userfile'

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.