JimmyJam Posted January 8, 2008 Share Posted January 8, 2008 Hi! How can i get this script: <?php if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> To add random numbers after the file name, so if people upload and happen to have named it the same thing, the random numbers after the file name will fix the problem? Quote Link to comment https://forums.phpfreaks.com/topic/85083-php-upload-script-random-numbers/ Share on other sites More sharing options...
nikefido Posted January 8, 2008 Share Posted January 8, 2008 look up math properties on php.net notably: rand - http://us3.php.net/manual/en/function.rand.php srand - http://us3.php.net/manual/en/function.srand.php mt-rand - http://us3.php.net/manual/en/function.mt-rand.php Check the comments on them for good usage techniques also! Quote Link to comment https://forums.phpfreaks.com/topic/85083-php-upload-script-random-numbers/#findComment-433951 Share on other sites More sharing options...
phpSensei Posted January 8, 2008 Share Posted January 8, 2008 I usually do... if(file_exists("upload/".$filename)){ $filename = explode(".",$filename); // << old way of doing this $filename = $filename[0].rand(300,7000).$filename[1]; $filename = str_replace("%20","_",$filename); $filename = str_replace(" ","_",$filename); } Although i have created my own script for this, much more complex and efficient. Quote Link to comment https://forums.phpfreaks.com/topic/85083-php-upload-script-random-numbers/#findComment-433955 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.