Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Using a customer's last name as an uploaded file name?

    I want to thank you all in advance for taking the time to look over my post and try to help me out here.

    So, I'm fairly clueless about PHP, and the only thing I have to go on are the small things I'm finding here on the web. Although, I'm having a really tough time finding exactly what I'm looking for. I've found a few posts with the same questions as mine (change user upload file name), but none that I can really understand...

    Okay. We have a simple form here with a text box and a file field.

    Code:
    <table width="100%" height="70" border="0">
      <tr>
        <td height="68">
    <form name="onephotoupload" enctype="multipart/form-data" method="post" action="http://customcameracollection.net/customerphotos/upload_file.php">
              <div align="center"> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
               
              <table width="100%" border="0">
                <tr> 
                  <td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                    <center>
    				<label>Last Name:</label> 
                      <input name="lastname" type="text" id="lastname" size="25">
                      <br /><input name="uploadedfile" type="file" id="uploadedfile" size="25">
                    </center>
                    </font></td>
                </tr>
                <tr> 
                  <td width="58%" align="right">
                      <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
                      <input type="submit" name="submit" value="Upload Photo" />
                      </font>
                    </td>
                </tr>
              </table>
     
              <br />
              </font></div>
            </form></td>
      </tr>
    </table>
    Now, I need a code that will take whatever the client types into the 'lastname' textbox and make it the new filename of the file that's uploaded to my FTP server. This way it would be easier for us to match up the client's photo with their order in which they placed. Each client will only be uploading one photo. No need for crazy numbers and letters and stuff.

    This is the PHP I've got so far:

    PHP Code:
    <?php

    $target_path 
    "uploads/";

    $target_path $target_path basename$_FILES['uploadedfile']['name']); 

    if(
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo 
    "The file ".  basename$_FILES['uploadedfile']['name']). 
        
    " has been uploaded";
    } else{
        echo 
    "There was an error uploading the file, please try again!";
    }
    ?>

    If someone could let me know the simplest way of going about doing this, I'd be incredibly grateful.

    Thanks again for taking the time to help me out!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Try
    PHP Code:
    $target_path "uploads/";

    $target_path $target_path rawurlencode$_POST['lastname']); 
    You need to validate the 'lastname' for empty string.

    PS:
    Quote Originally Posted by http://php.net/move_uploaded_file
    Warning : If the destination file already exists, it will be overwritten.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    stephmck990 (03-09-2009)

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ohio
    Posts
    254
    Thanks
    1
    Thanked 63 Times in 63 Posts
    You may want to take measures in the event whereby two or more users' last name clash as they will potentially end up erasing each other's pictures.

  • Users who have thanked shadowmaniac for this post:

    stephmck990 (03-09-2009)

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Awesome. Guys, thanks so much. I'll play around with how we want to end up doing this. (Might end up having the customer do last name, then first name separated by an underscore)

    Huge help.

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    (Might end up having the customer do last name, then first name separated by an underscore)
    ..until a situation comes where two customers have exactly the same first-name and last-name
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    ..until a situation comes where two customers have exactly the same first-name and last-name
    Doh!!!

    Hmm... any thoughts?

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    No need for crazy numbers and letters and stuff.
    If you are ready to change the above decision, then it's easy.
    You could append the auto_increment integer value from your table(assuming you are using such a DB setup) or just append a random number (see eg at http://php.net/manual/en/function.mo...file.php#85949)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    If you are ready to change the above decision, then it's easy.
    You could append the auto_increment integer value from your table(assuming you are using such a DB setup) or just append a random number (see eg at http://php.net/manual/en/function.mo...file.php#85949)
    Hmm. Actually I don't think we're keeping these images saved on the server for more than a day. Once they're uploaded, we're saving them into directories on our C drive. So I think we might be okay there.

    So now since we're only using this form for photos, isn't there code to restrict the file field from accepting anything other than just images? (We might want to accept Word documents too...)

    And also, size restrictions. We can't accept some dinky little cell phone photo for what our business does. Is there any way to keep client's from uploading a file under 50 kb?

    Thanks again guys. You are too awesome for words.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •