magebash Posted June 24, 2008 Share Posted June 24, 2008 This is my script: if ($userfile_size >100000){die("File too large. Try to reduce the size.");} if (!($userfile_type =="image/jpeg" OR $userfile_type=="image/gif")){$msg=$msg."Please only upload JPEG or GIF files.<BR>"; die("Please only upload JPEG or GIF files.");} $add="upload/$userfile_name"; if(move_uploaded_file ($userfile, $add)){ }else{echo "Failed to upload file. Please try again. If problem persists, contact administrator by logging in and using the Personal Message System.";} I was wondering if it is possible to rename the image uploaded to a random number. If possible how? Thanks. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 24, 2008 Share Posted June 24, 2008 you should the way I rename files on upload is <?php $ran_filename = date("U")."_".rand(0,999); ?> that gives you the a guaranteed random number. to rename use your own VAR in move_uploaded_file Quote Link to comment Share on other sites More sharing options...
magebash Posted June 24, 2008 Author Share Posted June 24, 2008 okay, but i need it to keep its extension. Quote Link to comment Share on other sites More sharing options...
magebash Posted June 24, 2008 Author Share Posted June 24, 2008 could you insert your code into mine to show how i could make it work? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 25, 2008 Share Posted June 25, 2008 Try something like: $userfile_name = date("U")."_".rand(0,999); RIGHT before the move_uploaded_file() call. Are you sure you want a random filename though? Quote Link to comment Share on other sites More sharing options...
magebash Posted June 25, 2008 Author Share Posted June 25, 2008 I am not sure, but I need someone to show me how to put it in my code and have it so the extension stays the same. Quote Link to comment Share on other sites More sharing options...
magebash Posted June 25, 2008 Author Share Posted June 25, 2008 well i figured it out. Thanks for your guys help. Quote Link to comment 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.