0

The PHP documentation doesn't explain what happens when there are two files being uploaded at the same time within the same session (two uploads running in two tabs of a browser).

Is there any way to track the progress of both uploads? Is the first upload status lost when the second one starts?

Thanks!

fabiocsg
  • 28
  • 3
  • Do you want to track the progress of both on the same tab or in every file tracked in the uploaded tab? – Mauro Sep 20 '13 at 12:00
  • I'd like to come up with something that allows me to track every file upload in the respective tab. – fabiocsg Sep 20 '13 at 13:50
  • So... do you want to track the upload progress on the client side? – Mauro Sep 20 '13 at 14:49
  • I need to display to the user the upload progress, if a user is uploading two different files in two different tabs I want to be able to display the progress of each file in the respective tab. I'd like to know how php deal with this kind of situation using his session upload progress feature. – fabiocsg Sep 20 '13 at 15:02

2 Answers2

1

Yes, it is possible to monitor the status on two different uploads in different tabs using PHP's Session Upload Progress feature. All you need to do is make the upload progress name different on both forms by changing the value="" parameter of the hidden upload progress name field.

For example, the upload form for tab 1 could look as follows:

<form action="upload.php" method="POST" enctype="multipart/form-data">

<input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="tab1">
<!-- notice the value="tab1" above -->

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="file" name="myUploadName" />
<input type="submit" />
</form>

Then, the upload form for tab 2 could look as follows:

<form action="upload.php" method="POST" enctype="multipart/form-data">

<input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="tab2">
<!-- notice the value="tab2" above -->

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="file" name="myUploadName" />
<input type="submit" />
</form>

Now that you have created two different upload progress sessions, you can get the progress data on the PHP side as follows:

$_SESSION['upload_progress_tab1'] // Progress data for tab 1
$_SESSION['upload_progress_tab2'] // Progress data for tab 2
data-dan
  • 76
  • 1
  • 1
0

This example could work for you:

http://www.johnboy.com/php-upload-progress-bar/

You need some client (JS) code and a bit of PHP

Mauro
  • 1,447
  • 1
  • 26
  • 46
  • I'm well aware that there are different approaches to achieve what I've asked, but the question is not "is there any alternative way to do this?"...It's more like "how does this method deal with this situation?" – fabiocsg Sep 21 '13 at 09:08