私は進行状況バーを表示するために 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 の私の php 構成
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