scheols Posted July 15, 2006 Share Posted July 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14659-randomly-rename-files-when-uploaded/ Share on other sites More sharing options...
hostfreak Posted July 15, 2006 Share Posted July 15, 2006 $name = substr(md5(mt_rand()), 5, 10) . substr($_FILES['thefile']['name'], -4);try changing 'thefile' to 'userfile' Quote Link to comment https://forums.phpfreaks.com/topic/14659-randomly-rename-files-when-uploaded/#findComment-58427 Share on other sites More sharing options...
scheols Posted July 15, 2006 Author Share Posted July 15, 2006 yeah that parts fixed now i need help changing the file name thats on my server.it went from :/613409f773 to /613409f773.txtbut that pade is still an error when i upload. i need the actuall file name changed. Quote Link to comment https://forums.phpfreaks.com/topic/14659-randomly-rename-files-when-uploaded/#findComment-58431 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.