I have been trying to setup an upload progress bar to my site using both apc and uploadprogress pecl but so far, i can only show the progress bar successfully for smaller files (around 100M😎 but not for files larger than 130MB. Initially, I used ajax to display the progress bar on the same page but it keeps returning blank values for larger files. At first, I thought it might be problem with APC or Uploadprogress Pecl but after i tried displaying the progress bar using javascript pop up windows instead of ajax, i noticed that in firefox, the popup windows displaying the progress bar will sometimes show an error message like the one show in IE about cannot display webpage or cannot connect to server. when i refresh the pop up windows, it can continues to show the progress correctly.
I have been trying for months to figure out this problem and hopefully someone out there can enlighten me. Many thanks in advance...
upload_form3a.php
<?php
set_time_limit(0);
$uid = md5(uniqid(rand()));
?>
<html>
<head>
<title>Upload Progess Bar</title>
<script type="text/javascript">
function newdow(uid) {
window.open('http://www.kuanpress.com.my/c/getprogress.php?uid=' + uid);
}
</script>
</head>
<body>
<form onSubmit="newdow('<?php echo $uid; ?>');" action="upload.php" method="post" enctype="multipart/form-data" name="upload" id="upload" target="upload_frame">
<input type="hidden" name="UPLOAD_IDENTIFIER" id="progress_key" value="<?php echo $uid; ?>" />
<input type="file" name="file" id="file" />
<input type="submit" name="submit" id="submit" value="Upload!" />
</form>
</body>
</html>
showprogress.php
<?php
set_time_limit(0);
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
?>
<html>
<head>
<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}
// -->
</script>
</head>
<body onload="JavaScript:timedRefresh(1000);">
<?php
if(isset($_GET['uid']))
{
$status = uploadprogress_get_info($_GET['uid']);
$current=$status['bytes_uploaded'];
$total=$status['bytes_total'];
$est=$status['est_sec'];
$suc=$status['files_uploaded'];
$lspeed=$status['speed_last'];
$aspeed=$status['speed_average'];
$stime=$status['time_start'];
$ltime=$status['time_last'];
$counter=$_GET["count"];
$counter=$counter+1;
$percent=floor($status['bytes_uploaded']/$status['bytes_total']*100);
$totalkb=round($total/1024);
$currentkb=round($current/1024);
$table="<table border=\"0\"><tr><td>
<table width=\"300\" style=\"border-width: 1px; border-color:#000000; border-style:solid;\" cellpadding=\"0\" cellspacing=\"0\">
<tr><td>
<table width=\"$percent" . "%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td bgcolor=\"#0000FF\"> </td></tr></table>
</td></tr>
</table></td><td>$percent" . "%a</td></tr></table>count=" . $counter;
$text=$table . "<br>transfering $currentkb" . " kBs of $totalkb" . " kBs<br>uid=" . $_GET['uid'] . "<br>estimate time=" . $est . "<br>uploaded file=" . $suc . "<br>last speed=$lspeed<br>average speed=$aspeed<br>time start=$stime<br>time_last=$ltime";
print("$text");
?>
</body>
</html>
upload.php
<?php
set_time_limit(0);
$path="/httpdocs/upload/";
$newdir="123";
$user = "xxxx";
$pass = "xxxx";
$server='ftp.example.com';
$direxist="n";
$ftpconnection2=ftp_connect($server);
$result=ftp_login($ftpconnection2, $user, $pass);
if ($ftpconnection2)
{
$listdirectory2=ftp_nlist($ftpconnection2, $path);
if ($listdirectory2)
{
foreach ($listdirectory2 as $directory)
{
$directory2=str_replace($path . "/", "", $directory);
if ($directory2==$newdir)
{
$direxist="y";
}
}
}
ftp_chdir($ftpconnection2, $path);
if ($direxist!="y")
{
$create=ftp_mkdir($ftpconnection2, $newdir);
}
ftp_chdir($ftpconnection2, $newdir);
$upload=ftp_put($ftpconnection2, $_FILES['file']['name'], $_FILES['file']['tmp_name'], FTP_BINARY);
if (!$upload)
{
print("<font color=\"#3366FF\" size=\"2\" face=\"Tahoma\">Upload Failed.<BR>If you experience the same problem again, please contact us.</font><BR>");
}
else
{
print("<font size=\"2\" face=\"Tahoma\">File uploaded successfully</font><BR>");
}
}
ftp_close($ftpconnection2);
?>