我正在使用APC(php)来显示进度条,但我陷入了困境。我使用过这个链接,所有内容都是写的,并且安装了APC。
http://www.johnboy.com/php-upload-progress-bar/
我使用相同的代码,修改路径很少,以存储我的链接
的图像http://way2enjoy.com/modules/music/try/try/upload.php
一切似乎都是正确的,但我案例中的进度条显示NaN%
我检查了显示此错误的错误日志
[23-Jun-2012 20:20:26 UTC] PHP Warning: Division by zero in /home/XXXXXXX/public_html/modules/music/try/try/upload_frame.php on line7
我的upload_frame.php代码是
<?php
$url = basename($_SERVER['SCRIPT_FILENAME']);
if(isset($_GET['progress_key'])) {
$status = apc_fetch('upload_'.$_GET['progress_key']);
echo $status['current']/$status['total']*100;
die;
}
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
<link href="style_progress.css" rel="stylesheet" type="text/css" />
<script>
$(document).ready(function() {
setInterval(function()
{
$.get("<?php echo $url; ?>?progress_key=<?php echo $_GET['up_id']; ?>&randval="+ Math.random(), {
},
function(data)
{
$('#progress_container').fadeIn(100);
$('#progress_bar').width(data +"%");
$('#progress_completed').html(parseInt(data) +"%");
}
)},500);
});
</script>
<body style="margin:0px">
<div id="progress_container">
<div id="progress_bar">
<div id="progress_completed"></div>
</div>
</div>
</body>
upload.php代码
<?php
$up_id = uniqid();
?>
<?php
if ($_POST) {
$folder = "tmp/";
$folder1 = "/home/XXXXXX/public_html/modules/music/try/try/";
$redirect = "upload.php?success";
move_uploaded_file($_FILES["file"]["tmp_name"], "$folder1" . $_FILES["file"]["name"]);
header('Location: '.$redirect); die;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Upload your file</title>
<link href="http://way2enjoy.com/files/common_css/style_progress.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
var show_bar = 0;
$('input[type="file"]').click(function(){
show_bar = 1;
});
$("#form1").submit(function(){
if (show_bar === 1) {
$('#upload_frame').show();
function set () {
$('#upload_frame').attr('src','upload_frame.php?up_id=<?php echo $up_id; ?>');
}
setTimeout(set);
}
});
});
</script>
</head>
<body>
<h1>Upload your file </h1>
<div>
<?php if (isset($_GET['success'])) { ?>
<span class="notice">Your file has been uploaded.</span>
<?php } ?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<br />
Choose a file to upload<br />
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
<input name="file" type="file" id="file" size="30"/>
<br />
<iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
<br />
<input name="Submit" type="submit" id="submit" value="Submit" />
我的APC配置
apc.cache_by_default On On
apc.canonicalize On On
apc.coredump_unmap Off Off
apc.enable_cli Off Off
apc.enabled On On
apc.file_md5 Off Off
apc.file_update_protection 2 2
apc.filters no value no value
apc.gc_ttl 3600 3600
apc.include_once_override Off Off
apc.lazy_classes Off Off
apc.lazy_functions Off Off
apc.max_file_size 1M 1M
apc.mmap_file_mask no value no value
apc.num_files_hint 1000 1000
apc.preload_path no value no value
apc.report_autofilter Off Off
apc.rfc1867 On On
apc.rfc1867_freq 0 0
apc.rfc1867_name APC_UPLOAD_PROGRESS APC_UPLOAD_PROGRESS
apc.rfc1867_prefix upload_ upload_
apc.rfc1867_ttl 3600 3600
apc.serializer default default
apc.shm_segments 1 1
apc.shm_size 32M 32M
apc.slam_defense On On
apc.stat On On
apc.stat_ctime Off Off
apc.ttl 0 0
apc.use_request_time On On
apc.user_entries_hint 4096 4096
apc.user_ttl 0 0
apc.write_lock On On
答案 0 :(得分:3)
答案 1 :(得分:1)
显然$status['total']
为零。
这样做:
if ($status['total'] == 0) {
echo "0";
}
else {
echo $status['current']/$status['total']*100;
}