PHP APC进度条 [英] PHP APC Progress Bar

查看:115
本文介绍了PHP APC进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Index.php

 <?php 
$ id = uniqid();
?>
< / head>

< body>
< form method =postaction =frame.phptarget =upload_iframeenctype =multipart / form-data>
< label for =file>文件名:< / label>
< input type =filename =fileid =file/>
< input type =hiddenname =APC_UPLOAD_PROGRESSid =progress_keyvalue =<?php echo $ id;?>/>
< br />
< input type =submitname =submitvalue =Submit/>
< / form>
< iframe name =upload_iframestyle =width:400px; height:100px;>
< / iframe>

frame.php

 <?php 
if(isset($ _ POST ['progress_key'])){
echohey1;
$ status = apc_fetch('upload _'。$ _ POST ['progress_key']);
echo $ status ['current'] / $ status ['total'] * 100;
}
echohey2;
?>

仍然不工作:(我甚至不会在框架中获取POST表单数据。错误?



Regards。

解决方案

上传机制,您需要添加一个额外的参数到您的窗体,标识正在上传的文件,是 apc_fetch 的关键。



<?php $ id = uniqid(time());?>



关键的 upload。$ id 中的值将包含你需要显示进度条的信息。最简单的方法是用ajax轮询服务器,使用 apc_fetch call you have。这意味着你的上传页面不需要刷新用户所在的当前页面我已经使用了一个 iframe 在过去启动一个我nterval轮询服务器。上传完成后,您可以在相同的iframe中显示完整的信息。


Post Updated: After commentors advice.

Index.php

<?php
$id = uniqid("");
?>
</head>

<body>
<form method="post" action="frame.php" target="upload_iframe" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $id; ?>"/>
<br />
<input type="submit" name="submit" value="Submit" />
</form>
<iframe name="upload_iframe" style="width: 400px; height: 100px;">
</iframe>

frame.php

<?php
if(isset($_POST['progress_key'])) {
    echo "hey1";
    $status = apc_fetch('upload_'.$_POST['progress_key']);
    echo $status['current']/$status['total']*100;
}
echo "hey2";
?>

Still doesnt work :(, I dont even get POST form data in frame. Where am i going so wrong?

Regards.

解决方案

Whenever you use the APC file upload mechanism, you need to add an additional parameter to your form that identifies the file that's being uploaded, and is the key for your apc_fetch.

<?php $id = uniqid(time()); ?>
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="myUniProgressKey" value="<?php echo $id; ?>"/>

As the file is uploaded the value in the key upload . $id will contain the info you need to display the progress bar. Easiest way to get to is to ajax poll the server, using the apc_fetch call you have. This dictates that your upload page needs to not refresh the current page the user is on. I've used an iframe in the past that kicks off an interval to poll the server. Once the upload is complete, you're able to show a nice complete message in the same iframe.

这篇关于PHP APC进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆