PHP APC 进度条

发布于 2024-10-14 17:55:59 字数 901 浏览 3 评论 0原文

帖子更新:根据评论者的建议。

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";
?>

仍然不起作用:(,我什至没有在框架中获取 POST 表单数据。我哪里错了?

问候。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔落墨 2024-10-21 17:56:00

每当您使用 APC 文件上传机制时,您都需要向表单添加一个附加参数,用于标识正在上传的文件,并且是 apc_fetch 的键。


当文件上传时,密钥中的值上传 . $id 将包含显示进度条所需的信息。最简单的方法是使用 apc_fetch 调用 ajax 轮询服务器。这表明您的上传页面不需要刷新用户所在的当前页面。我过去使用过 iframe 来启动轮询服务器的间隔。上传完成后,您可以在同一 iframe 中显示完整的消息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文