我目前正在开发一个使用 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"
?提前致谢!