dmagyar Posted April 16, 2008 Share Posted April 16, 2008 Hi Folks, I need to rename a photo upload with a member’s ID number (as opposed to randomizing the name). Can anyone point me to a solution? I included the working code below that needs the renaming feature added. ============================ Photo rename with upload ============================ To match a photo with a member, it is necessary for either (a) the member to manually name his or her photo with his or her member ID number or (b) have the system automatically rename it for him. At present, page "upload_photo.php" successfully uploads a file to directory "photos" (see code below). However, the photo uloaded is not identifiable with the member, plus it can be overwritten by anyone uploading a photo by the same name (such as "myphoto.gif"). The member's ID number is stored in a table named "members" and the ID field is "members_id". So, if member # “443” uploads a photo called “myphoto.gif”, the system should use the code below to upload the file, but rename the photo (with the renaming code) so that the resulting file appears in the “photos” directory as “443.gif”. Here is the code of "upload_photo.php" (it works): ==================================== <? $file_upload="true"; $file_up_size=$_FILES['file_up']; echo $_FILES[file_up][name]; if ($_FILES[file_up]>100000) { ?> <p class="center lower">Your file was <span class="red">NOT</span> uploaded.</p> <p class="center ">Please make your photo less than 100kb in size.</p> <?php $file_upload="false"; } $ext = strtolower(substr($_FILES['file_up']['name'], strrpos($_FILES['file_up']['name'], '.') + 1)); if (!($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif")) { ?> <p class="center lower somebottompadding">Your file was <span class="red">NOT</span> uploaded.</p> <p class="center morebottompadding">For security reasons, the file you upload must be in JPG, JPEG, PNG, or GIF format.</p> <?php // $msg .= "Please upload JPG, PNG, or GIF format only."; $file_upload = "false"; } $file_name=$_FILES[file_up][name]; // the path with the file name where the file will be stored. $add="photos/$file_name"; if($file_upload=="true"){ if(move_uploaded_file ($_FILES[file_up][tmp_name], $add)) { ?> <p class="center lower extrabottompadding">Your file has been successfully uploaded.</p> <?php }else{echo "Failed to upload file Contact Site admin to fix the problem";} }else{echo $msg;} ?> ================================== Thanks for your help. Don Quote Link to comment https://forums.phpfreaks.com/topic/101314-rename-photo-upload-with-member-id-number/ Share on other sites More sharing options...
tippy_102 Posted April 17, 2008 Share Posted April 17, 2008 Do the members have to be logged in to upload a file? If so keep their member id in a session and retrieve it for the file name. Quote Link to comment https://forums.phpfreaks.com/topic/101314-rename-photo-upload-with-member-id-number/#findComment-519158 Share on other sites More sharing options...
dmagyar Posted April 22, 2008 Author Share Posted April 22, 2008 Thanks for the reply. I'm sorry I didn't see it sooner. The answer to your question is yes, members are logged in. Your answer makes sense but converting it into code is another matter. Is anyone willing to modify the enclosed code? We use PayPal. Don Quote Link to comment https://forums.phpfreaks.com/topic/101314-rename-photo-upload-with-member-id-number/#findComment-523604 Share on other sites More sharing options...
Coreye Posted April 22, 2008 Share Posted April 22, 2008 Thanks for the reply. I'm sorry I didn't see it sooner. The answer to your question is yes, members are logged in. Your answer makes sense but converting it into code is another matter. Is anyone willing to modify the enclosed code? We use PayPal. Don Are you looking to pay someone to do it for you? If so, you should use the freelance section. (http://www.phpfreaks.com/forums/index.php/board,8.0.html) Quote Link to comment https://forums.phpfreaks.com/topic/101314-rename-photo-upload-with-member-id-number/#findComment-523712 Share on other sites More sharing options...
dmagyar Posted April 22, 2008 Author Share Posted April 22, 2008 It's a simple thing for you gurus or I wouldn't have asked for help. Naturally, I would appreciate the help without having to come out of pocket. Still, I'm going to the freelance section now. Thanks for the heads up. Quote Link to comment https://forums.phpfreaks.com/topic/101314-rename-photo-upload-with-member-id-number/#findComment-523750 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.