View Full Version : Uploading Images - General Question

11-09-2006, 06:22 PM
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.

11-09-2006, 10:20 PM
i would add an extra row (imglink) or similar, then img scr = "
<?php echo "$row[imglink]";// or something like that

11-10-2006, 12:33 AM
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:

<input type="file" name="pic1">

After submitting the form I'm not getting any values for the file names:

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.

11-10-2006, 12:41 AM
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

11-10-2006, 12:50 AM
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?)

11-10-2006, 01:20 AM
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 -

echo $_FILES['pic1']['error'];

11-10-2006, 06:36 AM
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.

11-10-2006, 10:22 PM
Well I re-wrote the code and now it works, I never did find the problem.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum