fcsg
fcsg

Reputation: 28

PHP session upload progress and simultaneous uploads

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!

Upvotes: 0

Views: 245

Answers (2)

data-dan
data-dan

Reputation: 106

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

Upvotes: 1

Mauro
Mauro

Reputation: 1487

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

Upvotes: 0

Related Questions