文件上载进度条 - 外部PHP文件未加载到div标签中

时间:2013-03-10 04:10:27

标签: php jquery upload progress-bar

在未能实现互联网上提供的大量上传状态教程后,我试图自己编写代码。为了给你一点背景,我有一个表格,允许用户提交照片和一些基本信息。提交后,将使用照片和用户提供的信息创建新页面。当我删除上传进度代码时,一切都很完美。首先,我在使用$来隐藏和显示div标签中的信息时遇到了一些问题。经过测试,我可以通过用jQuery替换$来使它们工作。现在问题本身:

<input class="usp_input" type="submit" name="user-submitted-post" id="user-submitted-post" value="<?php _e('Submit Post'); ?>" onclick="set()"/>

<div id="p-bar" name="p-bar"><span style="color:#dd0000"></span></div>
<div style="clear:both;"></div>


<script>
jQuery('#p-bar').hide();
</script>

<script>
function set()
{
  var pathname = "http://example.com/uploadstatus.php";
  jQuery('#p-bar').load(pathname);
  jQuery('#p-bar').show();
}
</script>

uploadstatus.php

<?php 
$uid = 12345;
$test=uploadprogress_get_info($uid);
$timerem = intVal($test['est_sec']);
if (intVal($test['bytes_total']) ==0)
{
  echo "Upload File Percentage = 0 % <br />";
  echo "Calculating Time Remaining. <br />";
}
else if ((intVal($test['bytes_total']) > 0) && ($timerem > 10)) 
{
  $pertrans = (intVal($test['bytes_uploaded']) / intVal($test['bytes_total'])) * 100; 
  $pertrans = number_format($pertrans, 2);
  echo "Upload File Percentage = "."$pertrans"."% <br />";
  echo "Estimated Time Remaining in Seconds = ".$timerem."<br />";
}
else if ((0 < $timerem) && ($timerem < 10))
{
  echo "Upload File Percentage = 100% <br />";
  echo "Almost complete…thanks for uploading and for your patience! <br />";
}
else 
{
}

?>

目前我手动设置$ uid,这是上传文件ID,但是一旦我开始工作,我计划更改它以允许多个用户同时上传。其次,我需要不断刷新uploadstatus.php页面。有什么想法我会怎么做呢?感谢。

0 个答案:

没有答案