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. Link to comment https://forums.phpfreaks.com/topic/111747-solved-image-uploading/ 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 Link to comment https://forums.phpfreaks.com/topic/111747-solved-image-uploading/#findComment-573646 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. Link to comment https://forums.phpfreaks.com/topic/111747-solved-image-uploading/#findComment-573649 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? Link to comment https://forums.phpfreaks.com/topic/111747-solved-image-uploading/#findComment-573654 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? Link to comment https://forums.phpfreaks.com/topic/111747-solved-image-uploading/#findComment-573708 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. Link to comment https://forums.phpfreaks.com/topic/111747-solved-image-uploading/#findComment-573710 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. Link to comment https://forums.phpfreaks.com/topic/111747-solved-image-uploading/#findComment-573758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.