douhuan3448 2013-01-13 23:31
浏览 52
已采纳

php表单进度条不起作用

Can someone spot the error in this code it is not displaying the upload progress.

<form action="upload.php" method="post" enctype="multipart/form-data">
<center><p> <input type='file' id='upload_id' size='58' style='height: 30px; font-size: 18px' name='filename'></p>
<input type='image' src='<?php echo $menu_upload_button; ?>' onclick="function set() { f=document.getElementById('progress_iframe'); f.style.display='block'; f.src='uploadprogress.php?id=<?=$upload_id?>';} setTimeout(set);">
<iframe id="progress_iframe" src="" style="display:none;" scrolling="no" frameborder="0"></iframe>
</form>

the function from the input is this:

function set() { 
   f=document.getElementById('progress_iframe'); 
   f.style.display='block'; 
   f.src='uploadprogress.php?id=<?=$upload_id?>';
} 
setTimeout(set);

uploadprogress.php:

<META HTTP-EQUIV='REFRESH' CONTENT='1;URL=?id=<?=$_GET['id']?>'>
Upload progress:<br />
<?php
    if(!$_GET['id']) die;
    $info = uploadprogress_get_info($_GET['id']);
    $kbytes_total = round($info['bytes_total'] / 1024);
    $kbytes_uploaded = round($info['bytes_uploaded'] / 1024);
    echo $kbytes_uploaded.'/'.$kbytes_total.' KB';
?>

Thank you.

  • 写回答

1条回答 默认 最新

  • dou7851 2013-01-13 23:49
    关注

    for starters, I'd suggested you rework using $_GET['id'] in your HTML, as that's a vector for a security breach (hitting that URL and passing in some nasty stuff). Perhaps check for an integer and sanitize that way the response from $_GET['id'].

    Also, if I may suggest, if you're connecting to the same site that you eliminate the iframe, as you can update in place elements on your page through ajax without the use of an iframe (which will be faster and more efficient, as it won't have to load a full page every time).

    If you keep this method, though, your javascript function will never end on your page, as your timeout function never has an end. You can do so with something like:

    var timer = setTimeout(
    clearTimeout(timer);
    

    A quick guess is that uploadprogress.php is in a different directory and you're giving it a relative URL instead of a full url. Try switching that (if it was in the htdocs/foo/bar dir on your server, set it to /foo/bar/uploadprogress.php

    Finally, the time parameter in setTimeout is required. You'll need to include that. Pop in a console.log or an alert in your setFunction to help you see how often that function is being called.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?