本文介绍了PHP上传进度会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 PHP 创建一个上传进度条.我看到了 PHP 5.4 的新特性:上传进度会话.
I am trying to create an upload progress bar with PHP.I saw the new feature of PHP 5.4: upload progress session.
这是我的 HTML 代码:
This is my HTML code:
<form id="upload" action="ajax/progress.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="dupload" />
<input id="file1" type="file" name="file1" />
<input class="btn primary" type="submit" value="Upload" />
</form>
这是progress.php:
And this is progress.php:
<?php
session_start();
$key = ini_get("session.upload_progress.prefix") . 'dupload';
if (!empty($_SESSION[$key])){
$current = $_SESSION[$key]["bytes_processed"];
$total = $_SESSION[$key]["content_length"];
echo $current < $total ? ceil($current / $total * 100) : 100;
}
else {
var_dump($_SESSION);
var_dump($_FILES);
}
AJAX:
$('#upload').submit(function () {
interval_id = setInterval(function () {
$.ajax({
url: "ajax/progress.php6",
type: "POST",
success: function (data) {
console.log(data);
}
});
}, 200);
return false;
});
所有的 ini 设置都是正确的.(会话已启用,名称和前缀正确)
All the ini settings are right. (session is enabled, name and prefix is right)
我总是得到一个空的会话数组.怎么了?
I am always getting an empty session array. What's wrong?
谢谢!
推荐答案
无法解决问题,所以我使用了 XMLHTTPREQUEST progress" 操作并且效果很好.谢谢!
Wasn't able to sort it out so I used XMLHTTPREQUEST "progress" action and that worked well.Thanks!
这篇关于PHP上传进度会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!