简单的PHP APC进度条

时间:2013-11-04 16:32:02

标签: php upload apc progress

我目前正在使用一个使用APC方法的php上传进度条。 您可以在此处查看此栏的更多内容:http://www.johnboy.com/php-upload-progress-bar/

这是我的upload.php代码:

<?php 
$up_id = uniqid(); 
if ($_POST) {
//specify folder for file upload
$folder = "tmp/"; 
$redirect = "upload.php?success";
move_uploaded_file($_FILES["file"]["tmp_name"], "$folder" . $_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="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>
<!--display bar only if file is chosen-->
<script>
$(document).ready(function() { 
//show the progress bar only if a file field was clicked
    var show_bar = 0;
    $('input[type="file"]').click(function(){
        show_bar = 1;
    });
//show iframe on form submit
    $("#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">
    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" />
  </form>
  </div>
</body>
</html>

upload_frame.php文件代码与原始代码相同:http://www.johnboy.com/php-upload-progress-bar/upload_frame.phps

在这种情况下一切正常,进度条显示所有内容。

问题是: 如果我为<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">设置action=""内容action="upload_handler.php",则上传进度条不再有效。

所以问题是我如何使用action="upload_handler.php"来完成这项工作? 提前谢谢!

0 个答案:

没有答案