views:

48

answers:

2

Hello,

I am using uploadify plugin of jquery and have set multiple files upload to true. How do i retrieve these files on the server side?

We need to specify file input name in files array $_FILES['fileInputName']. But i have only 1 file input present on the form which is submitting multiple files. How do i retrieve them all?

Thanks in advance :)

A: 

foreach

PHP:

foreach ($_FILE as $key => $value) {
    echo "_FILE : $key; Valor: $value<br />\n";
}

but if the jquery plugin sends the files one by one, you should save the data files in the user session.

if (!isset($_SESSION['FILES_UPLOAD']))
   $_SESSION['FILES_UPLOAD'] = array();

foreach ($_FILE as $key => $value) {
    $_SESSION['FILES_UPLOAD'][$key] =$value;
}
andres descalzo
Won't work with the specific way Uploadify works.
Pekka
Re your update: Storing files in the session is a *clever* idea. However, it has two downsides: 1. You will never be able to tell when it's the last file in the queue; and 2. You will experience mix-ups if the same user runs multiple uploads in different windows. You would have to send a unique key along to get around the latter - and before doing that, I really think you're better off using Uploadify's callbacks.
Pekka
Pecka, before you start an upload when the user hits start you would serialize the form and send that to the backend, now we know what files are expected to come, as each file comes in, you will remove from session until your down to your final file, read my comment above.
RobertPitt
Also @andres descalzo, theres no point in using session then is there because your code would not run until all the files are uploaded anyway.
RobertPitt
+3  A: 

Uploadify invokes an upload script for each uploaded file separately.

As far as I know, there is no way to tell inside the PHP upload script whether the current upload is the final one in the queue.

You need to make use of the onComplete and onAllComplete callbacks on client side. Inside onComplete, you would add each succeeded upload to an array. In onAllComplete, you could make an Ajax request sending the list of uploaded files to a PHP script.

Uploadify docs

Pekka
@Pekka : Nice. Exactly what i needed.
Ankit Rathod
you would have to individually assign uid's to the uploads and a also send a copy of the form serialized to the backed end to calculate how many files are going to be sent, and then after each file that has completed in the PHP side you will add a session variable , then an alternative javascript heartbeat to check against the backedend.. it is possible you just need to have the imagination and patients to get it just right. security is a big factor as well.. +1
RobertPitt