Php 为什么apc_fetch不返回上载进度?
我正在尝试获取文件上载的进度,但apc_fetch不会为此返回数组:Php 为什么apc_fetch不返回上载进度?,php,file-upload,xmlhttprequest,apc,Php,File Upload,Xmlhttprequest,Apc,我正在尝试获取文件上载的进度,但apc_fetch不会为此返回数组: $status = apc_fetch('upload_'.$_REQUEST['progress_key']); 文件上载成功完成,没有错误。我已启用apc.rfc1867。我知道APC_UPLOAD_PROGRESS必须是发送到服务器的第一个参数。我正在使用XMLHttpRequest上传,APC_UPLOAD_进度将以查询字符串的形式发送到服务器 上载正在我的服务器上的虚拟主机上进行。我在/etc/php.d/APC.
$status = apc_fetch('upload_'.$_REQUEST['progress_key']);
文件上载成功完成,没有错误。我已启用apc.rfc1867。我知道APC_UPLOAD_PROGRESS必须是发送到服务器的第一个参数。我正在使用XMLHttpRequest上传,APC_UPLOAD_进度将以查询字符串的形式发送到服务器
上载正在我的服务器上的虚拟主机上进行。我在/etc/php.d/APC.ini中启用了APC
以下是我用于上传的Javascript:
xhr.open('POST', queryURL, true); // queryURL var contains APC_UPLOAD_PROGRESS
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('X-File-Name', encodeURIComponent(filename));
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.send(input.files[0]);
当我使用iframe进行上传时,它在IE9中也不起作用
为什么apc_fetch不返回上载进度数组?演示url:--
您可以从此url下载jQuery文件并添加html标记
试试这个:-
//这是我的html标记
<!doctype html>
<head>
<title>File Upload Progress Demo #1</title>
<style>
body { padding: 30px }
form { display: block; margin: 20px auto; background: #eee; border-radius: 10px; padding: 15px }
.progress { position:relative; width:400px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; }
.bar { background-color: #B4F5B4; width:0%; height:20px; border-radius: 3px; }
.percent { position:absolute; display:inline-block; top:3px; left:48%; }
</style>
</head>
<body>
<h1>File Upload Progress Demo #1</h1>
<code><input type="file" name="myfile"></code>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploadedfile"><br>
<input type="submit" value="Upload File to Server">
</form>
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
bar.width("100%");
percent.html("100%");
status.html(xhr.responseText);
}
});
})();
</script>
</body>
</html>
我的php代码:
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
您的APC\u UPLOAD\u PROGRESS
隐藏字段是否位于表单中文件输入标记之前 我想你需要进度条时文件上传时间。我说得对吗?没错。但是为了让进度条工作,我需要用apc_fetch检索上传进度数据,这是我无法做到的。我的答案中有发送代码,我正在使用jQuery进度条和php中的文件上传。请看一看。我期待着看一下,但我要解决的问题是在服务器端——apc_fetch函数没有返回我期望的值。我在实际上传文件时没有遇到任何问题。谢谢你的提示Jeroen,我在1页上可以正常工作,但无法找出为什么在第2页上不能正常工作。@Jeroen Moons。APC可以用于获取单个文件的进度吗?@Samir如果您在上传表单中有一个文件输入,您可以提供一个自己生成的密钥(名为“progress_key”的隐藏字段),然后向APC请求该密钥的进度(这样您就可以获得该文件的进度)。如果您在一个表单中有多个文件输入,我不确定是否可以使用这种方法进行跟踪。您应该能够为每个文件输入绑定一个键,但我不知道这是否可行。@Jeroen Moons。谢谢我只是想知道是否有人尝试过,看看它是否有效。所有示例都指向单个表单级别的上载进度状态。我想我得试着检查一下自己。@Samir没问题。如果您在调查后了解更多,请在此处发布一些反馈。