TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

Uploading Multiple Files... Empty Fields?

Page: 1 Reply
Oct 26th 2004#161932 Report
Member since: Mar 18th 2001
Posts: 6632
I'm creating a site where you can upload pictures to the web site, and then we print them and mail them to you, like www.shutterfly.com or www.ofoto.com.

The customer can upload 10 photos at once. I have it working right now where you can upload 1 file, and everything works great. The info is inserted in the database, the image is uploaded, directories are created, a thumbnail is created, etc etc.

But when I try to make it work where you can upload all 10 files, I'm having trouble.

Everything still works, the files are uploaded, but I'm getting errors for all of the fields that are empty. For instance if the customer only fills 3 out of the 10 File Browse boxes, those 3 images are uploaded correctly, but I get several error messages for all of the empty files:

An error occurred in script /home/violet/public_html/newsite/includes/config.inc on line 11: getimagesize(../uploads/11/343.): failed to open stream: No such file or directory

An error occurred in script /home/violet/public_html/newsite/includes/config.inc on line 11: Division by zero

An error occurred in script /home/violet/public_html/newsite/includes/config.inc on line 11: imagecreatefromjpeg(../uploads/11/343.): failed to open stream: No such file or directory

An error occurred in script /home/violet/public_html/newsite/includes/config.inc on line 11: Undefined offset: 1



Here is the code I'm using on the page where they choose the files to upload, "upload.php"

[CODE]
< input type="file" size="25" tabindex="1" name="userfile[]" />
< input type="file" size="25" tabindex="2" name="userfile[]" />
< input type="file" size="25" tabindex="3" name="userfile[]" />
< input type="file" size="25" tabindex="4" name="userfile[]" />
< input type="file" size="25" tabindex="5" name="userfile[]" />
< input type="file" size="25" tabindex="6" name="userfile[]" />
< input type="file" size="25" tabindex="7" name="userfile[]" />
< input type="file" size="25" tabindex="8" name="userfile[]" />
< input type="file" size="25" tabindex="9" name="userfile[]" />
< input type="file" size="25" tabindex="10" name="userfile[]" />
[/CODE]

Which is using the method suggested in the PHP manual: http://aspn.activestate.com/ASPN/docs/PHP/...d.multiple.html

I have also found the method linked to here (the google cache page): http://www.dmcinsights.com/phorum/read.php...10220#msg-10220

And both generate the same errors.

Here is the code I'm using for the viewpictures.php page, which upload.php points to:

[PHP]
// start loop to process all pictures uploaded.
for ($x = 0; $x <= 9; $x++) {

if (isset($_FILES['userfile']['size'][$x])) {

//Do all of the same image processing I did with the single image...

}
}
[/PHP]

Like I said, everything still uploads correctly, but it seems to be looking for data in the empty fields, even though they are empty.

Is something wrong about my "if" statement? Shouldn't it skip all of the image processing if that variable is empty? Or does the browser send some sort of variable even if the File box is empty?


Sorry this was so long, just wanted to explain everything thoroughly. Thanks for any help you can provide.
Reply with Quote Reply
Oct 26th 2004#161938 Report
Member since: Apr 20th 2002
Posts: 3000
If a variable is empty then it is set. $string = ""; is empty and set.

The way that the form submits data is an array, $userfile, which will put into the appropriate indecies the files that the client had put in and have the other ones empty. What you would want to do is to check if the file exists. Since files that are uploaded thru the forms are saved in a temporary directory, you can use the $file_exists(String path) function. If, for example, the client uploaded only three files, then the script would check to see if all the entries in the array $userfile exist. Since only the three files the client uploaded exists, the script wouldn't bother to execute the code within the if statement for the following ones.

btw this is off the top of my head. I'd have to go and check up on the details.
Reply with Quote Reply
Oct 26th 2004#161939 Report
Member since: Mar 18th 2001
Posts: 6632
Thanks for the help moochan.

I changed it to: if (!empty()) and it works fine now.
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum