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!

4

2 回答 2

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
于 2014-01-04T22:32:52.653 回答
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

于 2013-09-20T15:05:49.217 回答