Multiple selection / multiple upload

See all posts Reply

Multiple selection / multiple upload new!
by Mdc888, 14 years, 1 month ago
Hi there,

I really like your job; this class is useful and working perfectly...

Just a suggestion:
Do you think that could be possible to allow a multiple selection of files, aiming a multiple upload?

It could be really useful in many cases;
I know Google is doing this in Gmail, but maybe it's difficult to program...

Thanks!Reply
Re: Multiple selection / multiple upload new!
by colin, 14 years, 1 month ago
The class supports multiple uploads, check the faq, section called What about multiple uploads?.

That said, the actual widget to upload several files at the same time is a client-side problem. You can use the class with any upload system, multiple or not. In other words, the class deals with the upload, not with the upload form.Reply
Re: Multiple selection / multiple upload new!
by Mdc888, 14 years ago
Thank you for the answer...
I thought I checked the FAQ...

Otherwise the code :
$files = array();
foreach ($_FILES['my_field'] as $k => $l) {
  foreach ($l as $i => $v) {
    if (!array_key_exists($i, $files))
      $files[$i] = array();
    $files[$i][$k] = $v;
  }
}

Seems to be buggy... Executing it always give me an error on the line:
foreach ($l as $i => $v) {

The server is running PHP version 5.2

Do you have any idea?

ThanksReply
Re: Multiple selection / multiple upload new!
by colin, 14 years ago
What is the error that you get? Can you dump here the content of the $_FILES array()?Reply
Re: Multiple selection / multiple upload new!
by Mdc888, 14 years ago
Mmh...

I should have been done by myself...

Here is the content of the array :
Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 )

I think this error is finally due to my field...

It's still a simple form:
<input type="file" size="32" name="my_field" value="" />
<input type="hidden" name="action" value="image" />
<input type="submit" name="Submit" value="upload" />

What should I use here?

Thanks!Reply
Re: Multiple selection / multiple upload new!
by colin, 14 years ago
You have an error 4 : UPLOAD_ERR_NO_FILE. So no file was uploaded.

Are you sure your form tag has the property enctype="multipart/form-data"?Reply
Re: Multiple selection / multiple upload new!
by Mdc888, 14 years ago
Yeah, that's one of the first thing I checked.

Do you want me to upload my entire source code?Reply
Re: Multiple selection / multiple upload new!
by Mdc888, 14 years ago
By the way, here it is:
<fieldset>
  <legend class='titrenoir'>Image upload</legend>
  <form name='form' enctype='multipart/form-data' method='post' action='upload_server_V5.php?upload_type=images' />
  <p><input type="file" size="32" name="my_field" value="" /></p>
  <p class="button"><input type="hidden" name="action" value="image" />
  <input type="submit" name="Submit" value="upload" /></p>
  </form>
</fieldset>

(Translated in HTML)Reply
Re: Multiple selection / multiple upload new!
by colin, 14 years ago
I am not sure why you have an error. In any case, the error 4 UPLOAD_ERR_NO_FILE means that no file has been uploaded. The class cannot do anything if no file has been uploaded, and is not even activated. Check if uploads work properly on your server., without the class. Then use the class.Reply
Re: Multiple selection / multiple upload new!
by Mdc888, 14 years ago
Yeah, sorry about that; This problem is now solved :
Array ( [name] => DSC_0003.JPG [type] => image/jpeg [tmp_name] => /var/log/tmp/phpPXNx11 [error] => 0 [size] => 3549618 )

BUT I still have the same problem :
Warning: Invalid argument supplied for foreach() in xxx.php on line 117

Talking about something else: how could you select multiple files with the normal input form?

ThanksReply
Re: Multiple selection / multiple upload new!
by colin, 14 years ago
The foreach() loops are to be used only if you have multiple upload fields.

In your case, you have only one field my_field. You can instanciate the class directly without looping through the $_FILES array.

If you want multiple upload fields, you need to have several fields in your form, and then you will have to loop through $_FILES as in the FAQ. To have several fields, you would need to have something like this in your form:
<input type="file" size="32" name="my_field[]" value="" />
<input type="file" size="32" name="my_field[]" value="" />
<input type="file" size="32" name="my_field[]" value="" />
Reply
Re: Multiple selection / multiple upload new!
by Mdc888, 14 years ago
Right, that's what I thought...
Now that's working perfectly...

Thank you so much for your help.

Otherwise here is a link to a multiple selection solution;
http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/
it's opensource and I think that's completing your uploading class...Reply