graham23s Posted May 5, 2007 Share Posted May 5, 2007 Hi Guys, i currently use this script for uploading: <?php $photo1 = $_FILES["image1"]["name"]; $username = mysql_real_escape_string($_POST["username"]); $max_image_size = 512000; $allowed = array("image/gif","image/jpg","image/x-png","image/jpeg"); $max_image_width = 500; $max_image_height = 450; $random_number = rand(0000,9999); // Query for a previous photo.../////////////////////////////////////////////////////// $result = mysql_query("SELECT photo1 FROM membership WHERE username='".$username."' LIMIT 1"); $row = mysql_fetch_object($result); $photo_to_delete = $row->photo1; unlink("uploads/".$photo_to_delete); // The renamed photo...//////////////////////////////////////////////////////////////// $renamed_photo = $random_number.$username.$_FILES["image1"]["name"]; // Check there wasn't a blank submission...//////////////////////////////////////////// if(empty($_FILES["image1"]["name"])) { echo "<p>Sorry, But No File Was Selected, Please Go Back And Try Again.</p>"; exit; } // Validation for Image... if ($_FILES["image1"]["size"] > $max_image_size) { echo "<p>Sorry <b>$username</b> That Image Is Bigger Than The Allowed Size Of 3mb Please <a href=\"java script: history.go(-1)\">Go Back</a></p>"; exit; } ##################################################################### // Validate image dimensions...//////////////////////////////////////////////////////// $dim = getimagesize($_FILES["image1"]["tmp_name"]); if($dim[0] >= $max_image_width || $dim[1] >= $max_image_height) { echo "<p>Sorry, That Image Isn't Within The Current Upload Dimensions Please Go Back And Upload Another!</p>"; exit; } // Validate image types...///////////////////////////////////////////////////////////// if (in_array($_FILES["image1"]["type"], $allowed)) { echo "<p>Sorry, That File Isn't One Of The Allowed File Types Only <b>.jpg & .png</b> Are Allowed.</p>"; exit; } ##################################################################### $uploadpath = "uploads/"; // <- Upload folder... $uploadpath = $uploadpath.$renamed_photo; ##################################################################### if (!move_uploaded_file($_FILES["image1"]["tmp_name"], $uploadpath)) die("<p>Sorry, There Was An Error Uploading Your Image!"); echo "<p><br />The Image (<b><font color=\"red\">" .$_FILES["image1"]["name"]. "</b></font>) Has Been Uploaded Successfully!<br />"; echo '<br /><p>Please Wait To Be Re-Directed...</p>'; echo "<meta http-equiv=\"refresh\" content=\"3;URL=javascript: history.go(-1)\">"; // Create our query...///////////////////////////////////////////////////////////////// $sql = "UPDATE membership SET photo1='$renamed_photo' WHERE username='$username'"; // Run our query...//////////////////////////////////////////////////////////////////// $rs = mysql_query($sql, $conn) or die(mysql_error()); ?> this appends some random digits to the uploaded photo, what i was wanting to do is just entirely make the photo random digits e.g 123456.jpg and appednd .jpg to the end of each, but not sure how to go about it , any help would be appreciated Graham Quote Link to comment https://forums.phpfreaks.com/topic/50138-solved-re-naming-an-uploaded-photo/ Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 try $renamed_photo = $random_number.$username.$_FILES["image1"]["name"]; to $renamed_photo = random_number.substr($_FILES["image1"]["name"],strlen($_FILES["image1"]["name"])-3,3); Quote Link to comment https://forums.phpfreaks.com/topic/50138-solved-re-naming-an-uploaded-photo/#findComment-246180 Share on other sites More sharing options...
graham23s Posted May 5, 2007 Author Share Posted May 5, 2007 Hi Mate, that gave me this: random_numberjpg in the uploads folder, but it is what im after only a little wrong lol Graham Quote Link to comment https://forums.phpfreaks.com/topic/50138-solved-re-naming-an-uploaded-photo/#findComment-246245 Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 lol oops $renamed_photo = $random_number.".".substr($_FILES["image1"]["name"],strlen($_FILES["image1"]["name"])-3,3); updated Quote Link to comment https://forums.phpfreaks.com/topic/50138-solved-re-naming-an-uploaded-photo/#findComment-246249 Share on other sites More sharing options...
graham23s Posted May 5, 2007 Author Share Posted May 5, 2007 Perferct Mad Tech, thanks mate:) Graham Quote Link to comment https://forums.phpfreaks.com/topic/50138-solved-re-naming-an-uploaded-photo/#findComment-246251 Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 Coolie can you click solved (if thats the case) Quote Link to comment https://forums.phpfreaks.com/topic/50138-solved-re-naming-an-uploaded-photo/#findComment-246253 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.