I am using this function here:
http://www.php.net/manual/en/session.upload-progress.php
And here is my code for the progress uploading:
<?
session_start();
$key = ini_get("session.upload_progress.prefix") . "myForm";
if(!empty($_SESSION[$key])) {
echo "<table width='400' style='font-family: Verdana; font-size: 12px;'>";
foreach($_SESSION[$key]['files'] as $f)
{
// Get percentage done
$current = $f["bytes_processed"];
$total = $f["content_length"];
if($current < $total) {
$done = ceil($current / $total * 100);
} else {
$done = 100;
}
echo " <tr>
<td colspan=2>{$f['name']}</td>
</tr>
<tr>
<td colspan=2><img src='uploading.gif' width='{$done}px' height='13px'></td>
</tr>
<tr>
<td>Started @ ".date("H:m:s",$f['start_time'])."</td>
<td>{$done}%</td>
</tr>";
}
echo "</table>";
}
?>
The problem is that the individual files do not have a content_length
variable. How can I work the progress for each file that is uploaded?
You can't, unless you're uploading a single file. $_SESSION[$key]['content_length']
is the total content length of the files that are being uploaded and the only indication of content length available. So you have two options: show a global progress of all files or limit the number of uploaded files to 1.
(Not sure if you are, but if you're willing to ditch this method you could opt for one of the numerous upload managers available. In the past I've used Fine Uploader with satisfaction.)