3

HTML:

                        <input type="file" value="choose file" name="file[]" multiple="multiple"/><br/>
                        <input type="submit" class="submit" value="confirm" />
                        <input type="hidden" name="uploadFiles" />

</form>

PHP:

if (isset($_POST['uploadFiles'])) {
  $fileCount = count($_FILES["file"]["name"]);
  for ($i = 0 ; $i < $fileCount ; $i++ ) {
      checking......
       move_uploaded_file($_FILES["file"]["tmp_name"][$i],$fileName);
  }
}

Currently I am using the above way to upload the files, I found that the Jquery UI provide the progress bar function but I have to provide the upload status to it. Therefore, what approach I can choose to get the status?

user782104
  • 13,233
  • 55
  • 172
  • 312
  • 2
    http://www.php.net/manual/en/session.upload-progress.php – deceze Mar 19 '13 at 09:50
  • why you are not using jquery plugins? http://blueimp.github.com/jQuery-File-Upload/ – Sibiraj PR Mar 19 '13 at 09:52
  • For an out-of-the-box solution, look at [Uploadify](http://www.uploadify.com/). – Knelis Mar 19 '13 at 09:52
  • php upload progress is feasible? Since I am using $_POST['uploadfile'] to check whether the user has press confirm button, and the $post will display message only after everything is complete (the upload is complete)? – user782104 Mar 19 '13 at 09:55
  • again, $_POST will display the echo message only after everything is complete... How to update the % ? thanks – user782104 Mar 19 '13 at 10:04
  • 1
    You have to make parallel requests to the server using AJAX, to query for the current upload progress. – CBroe Mar 19 '13 at 10:10

2 Answers2

2

My recommendation is to download an already built ajax files upload script and study it a bit as they are quite complex to paste as a reply.

I just had a look at my scripts and it seems that the progress it's actually on the JS side, not in the php.

If you have upgraded to php 5.4 you can use

http://www.php.net/manual/en/session.upload-progress.php

aleation
  • 4,796
  • 1
  • 21
  • 35
  • Thanks for suggesting the PHP solution , sorry I am quite confused in the implementation , Does it mean what I need to do is use a while loop and execute ini_get for , say , 1 second, and get the processed/total % and pass to jquery ui progress bar? – user782104 Mar 19 '13 at 10:01
1

If you have PHP 5.4, you can use this method. Check the information on the php website: http://php.net/manual/en/session.upload-progress.php

If you are not in PHP 5.4, the same thing can be done with APC Check this out: http://www.ibm.com/developerworks/library/os-php-v525/index.html

However, many jQuery plugins use embedded flash, which they can retrieve information from. Such as mentioned above: Uploadify

André Catita
  • 1,313
  • 16
  • 19
  • Thanks for suggesting the PHP solution , sorry I am quite confused in the implementation , Does it mean what I need to do is use a while loop and execute ini_get for , say , 1 second, and get the processed/total % and pass to jquery ui progress bar? – user782104 Mar 19 '13 at 10:02
  • You need to define a timeout of sorts in JavaScript, (setTimeout) and regularly check the progress, until you know it's over. – André Catita Mar 19 '13 at 10:03
  • that means using ajax to call the checking.php and that php is to execute ini and format the process bytes to %? – user782104 Mar 19 '13 at 10:08