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
    Regular Coder
    Join Date
    Jul 2003
    Posts
    262
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Uploading Images - General Question

    I have a php front end to a mysql database that I developed for use at work. Our employees can add and remove items from the database, which represents a list of parts we have on our shelf. I have been asked to add one (or more) pictures for each record in the database.

    Before I start working on this I wanted to ask if anyone has a recommendation on the best method to acomplish this. I was thinking about just uploading the images to a directory under our web root, and store the file names in the database, maybe have up to 3 pics per record. When the table is built to display all the available items I'd just add the required links.

    Does this sound OK?

    I know from setting up Gallery they recommend NOT putting the images directory under the webroot (for security reasons I believe?). I had considered this but honestly I don't know why I'd need to, and on top of that I don't know how to upload to directories above my web root (any tips appreciated).

    One other thing I had considered is renaming the images to match the ID in the database. We actually print the ID out and tag the parts with it, so it might be nice to rename the images with the corresponding ID. I don't know exactly how to do this, although I'm sure it can't be difficult.

    Any suggestions and feedback that will save me some time and headache are appreciated.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    i would add an extra row (imglink) or similar, then img scr = "
    PHP Code:
    <?php echo "$row[imglink]";// or something like that
    ?>"

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Posts
    262
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That's what I ended up doing. I limited it to 3 pics per record, so added 3 fields to each record.

    One question though - what would cause my $_FILES array to be empty when my form is posted?

    Here is the form field:
    PHP Code:
    <input type="file" name="pic1"
    After submitting the form I'm not getting any values for the file names:
    PHP Code:
    echo $_FILES['pic1']['name'];
    echo 
    $_FILES['pic1']['tmp_name']; 
    Also isset($_FILES['pic1']['tmp_name']) returns false (I assume all the array values would return false but didn't test them all). Just to make sure I was posting OK I checked the $_POST value for the field and it is ok as expected. I'm at a loss.
    Last edited by mothra; 11-09-2006 at 11:37 PM.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Here are the three most common reasons for a null $_FILES array -

    1) Uploads are not enabled on your server

    2) The form enctype= is not set at all or not set correctly

    3) The upload file size exceeds the POST_MAX_SIZE directive in php.ini
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    Jul 2003
    Posts
    262
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks. I just ran phpinfo() and noticed the following:

    post_max_size = 55m (not a problem)
    upload_max_filesize = 2m (not a problem right now)
    upload_tmp_dir = no value (is this a problem?)

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    A blank upload_tmp_dir is supposed to use the default temp folder, so this should not be a problem.

    Actually, the reasons I gave result in a completely null $_FILES variable. It is possible that you are only getting specific elements that are not set, take a look at the ['error'] element -
    PHP Code:
    echo $_FILES['pic1']['error']; 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    Regular Coder
    Join Date
    Jul 2003
    Posts
    262
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks. I had checked that after posting and it was not set either. My server supports file upload, and my form enctype is set properly. Any other ideas? I'll take another look over my code in the morning, I'm probably missing something obvious.

  • #8
    Regular Coder
    Join Date
    Jul 2003
    Posts
    262
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well I re-wrote the code and now it works, I never did find the problem.


  •  

    Posting Permissions

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