[英]uploadprogress_get_info installed correctly and but not working in different code
[英]uploadprogress extension : uploadprogress_get_info always returning null
我想在上传代码中添加进度条,因此我安装了uploadprogress扩展名(实际上,我已经将wamp服务器降级为wamp 2.0,因为该服务器已经具有扩展名,但是新版本似乎有问题)
这是我的后端代码
//////////////////上传
<?php
if (isset($_POST['upload'])) {
echo 'UPLOADING . . . <br />';
$location = './uploads';
$new= uniqid().'.'.end(explode('.' , basename($_FILES['mailfile']['name']) ));
if(move_uploaded_file( $_FILES['mailfile']['tmp_name'],"$location/$new"))
echo 'DONE !! ';
else
echo 'error';
}
///////////////获取上传信息
else if(isset($_GET['get_info']))
{
if (function_exists("uploadprogress_get_info")) {
$info = uploadprogress_get_info($_GET['get_info']);
} else {
$info = 'nofunc';
}
var_dump($info);
}
///////////////上传表格
else
{ $uploadID = substr(md5(microtime(true)), 0, 10);
?>
<form enctype="multipart/form-data" action="uploadprogress.php" method="post" >
<input type="text" name="UPLOAD_IDENTIFIER" value="<?php echo $uploadID; ?>" id="uploadIdentifier" />
<input id="file" name="mailfile" type="file" />
<input type="submit" value="Send File" id="btn" name="upload" />
</form>
<?php
}
这是我上传文件时的前置html / jquery代码,它从iframe获取UPLOAD_IDENTIFIER值,并将其发送到set()函数,该函数假定是通过ajax调用来获取上传进度,但始终返回null
<html>
<head>
<script language="javascript" src="../../js/jquery.js"></script>
<script>
var val;
$(function(){
$('#progress_iframe').load(function() {
var ifr = $(this);
$(this)
.contents()
.find('#btn')
.bind('click', function() {
val = ifr.contents().find('#uploadIdentifier').val();
set();
// do stuff
});
});
})
function set() {
$.get('uploadprogress.php' , {get_info : val} , function(data){
data = $.trim(data);
$('#info').html(data) ;
if(data < 100 )
set();
})
}
</script>
</head>
<body>
<div>
<iframe id="progress_iframe" src="uploadprogress.php" frameborder="0"> </iframe>
<span id="info"></span>
</div>
</body>
</html>
因此文件正在上传而没有任何问题,我尝试了一个大文件,但由于文件正在上传,uploadprogress_get_info为null
检查服务器上是否可以访问UploadProgress tmp目录。 意思是“ uploadprogress.file.filename_template”是指phpinfo中正确的tmp文件夹。
您可以运行以下代码进行检查。
<div id =“ status” style =“ border:1px黑色固体; <?php
$ templateini = ini_get(“ uploadprogress.file.filename_template”);
$ testid =“ thisisjustatest”;
$ template = sprintf($ templateini,$ testid);
$ templateerror =假;
如果($ template && $ template!= $ templateini && @touch($ template)&& file_exists($ template)){
//打印'('。$ templateini。'是可写的。真实路径为'。str_replace($ testid,“%s”,realpath($ template))。')';;
unlink($ template);
}其他{
$ templateerror = true;
}
如果(function_exists(“ uploadprogress_get_info”)){
如果($ templateerror){
打印'background-color:red;“';
打印“>问题。”;
如果($ template == $ templateini){
打印“ uploadprogress.file.filename_template($ templateini)里面没有%s来制作唯一的临时文件。请调整。<br/>”
}其他{
打印“ $ templateini是不可写的。<br/>请确保该目录存在并且对于Web服务器是可写的。<br/>
或者将ini设置“ uploadprogress.file.filename_template”调整为正确的路径。”
}
}其他{
print'background-color:green;“>已经安装了uploadprogress扩展,初步检查显示一切都很好”;
}
}其他{
?>
background-color:red;“>未安装uploadprogress扩展名。
<?php}?>
</ div>
如果以上代码给出错误,请指向php.ini文件中正确的tmp目录。 在Windows本地计算机上的Xampp tmp目录的php.ini文件中添加了以下行。 uploadprogress.file.filename_template = C:\\ xampp \\ tmp \\ some_name_%s.txt
现在您的代码应该可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.