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 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP's $_FILES properties

    I was wondering if there was a way to retrieve the FULL path of the location of the file before it is uploaded. Reason being is I have a form with lets say 3 places to input data. Two are text and one is a file. However if they forget to input text into one of the input fields, it will prompt them to insert that into the field, and what I do is i assign the value of the other field to itself, so it essentially remembers what they had typed in. However I can't seem to get the full file extension of the image they are uploading.

    here is example.

    PHP Code:
    <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="image">
            <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
                <table width="320" border="0" cellpadding="3" cellspacing="0" align="center">    
                  <tr>
                      <td width="82">Image:</td>
                    <td width="9"><?php if ($errors['image']) echo '<img src="images/arrow.jpg">'?></td>
                    <td width="205"><input name="userfile" type="file" size="18" <?php if (!$errors['image_name']) echo $_FILES['userfile']; ?> /></td>
                  </tr>
                  <tr>
                      <td>Doc Name: </td>
                    <td>&nbsp;</td>
                    <td><input name="doc_name" type="text" size="18" maxlength="50" disabled /></td>
                  </tr>
                  <tr>
                      <td>Image Name:</td>
                    <td><?php if ($errors['image_name']) echo '<img src="images/arrow.jpg">'?></td>
                    <td><input name="image_name" type="text" size="18" maxlength="20" <? if (!$errors['image_name']) echo "value=\"".$_POST['image_name']."\""?> /></td>
                  </tr>
                  <tr>
                      <td>Description:</td>
                    <td><?php if ($errors['description']) echo '<img src="images/arrow.jpg">'?></td>
                    <td><input name="description" type="text" size="18" maxlength="50" <?php if (!$errors['description']) echo "value=\"".$_POST['description']."\""?> /></td>
                  </tr>
                  <tr>
                    <td colspan="3"><hr /></td>
                  </tr>
                  <tr>
                    <td align="center" colspan="3"><input type="submit" name="submit" value="Submit" /></td>
                  </tr>
                </table>
    </form>
    Basically the main line of code is this

    <?php if (!$errors['image_name']) echo $_FILES['userfile']; ?>

    if they uploaded a good image.. passed my tests (I didn't include that code as it isn't necessary) I want it to remember the path of where the image was on the users local hard drive, while they correctly fill in the other fields in the form.

    Any help?

    Thanks in advance

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can use this:
    http://www.codingforums.com/showpost...82&postcount=5
    but you should be doing client side validation or at least caching the uploaded file since they'd be essentially uploading the file twice with what you want to do.

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how would i cache the file?

  • #4
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marf
    how would i cache the file?
    move it to a temporary directory and contain a reference to that file via a session/cookie/db. or use JS validation to prevent it from happening (not a perfect solution but practical).


  •  

    Posting Permissions

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