PHP会话上传进度和同步上传

问题描述:

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!

PHP 文档没有解释当在同一个会话中同时上传两个文件时会发生什么(两个上传在浏览器的两个选项卡中运行)。 p >

有没有办法跟踪两个上传的进度? 第二个上传状态在第二个上传时失去了吗? p>

谢谢! p> div>

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

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