Jump to content

Recommended Posts

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

 

 

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

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.