成功上傳后,我試圖重定向到另一個頁面。
所以我在stackoverflow上搜索了類似的答案,但似乎沒有解決我的問題。
這是我的表格:
<form enctype="multipart/form-data"
action="<?php print $_SERVER['PHP_SELF']?>" method="post">
<p><input type="hidden" name="MAX_FILE_SIZE" value="9000000" /> <input
type="file" name="pdfFile" /><br />
<br />
<input type="submit" value="upload" /></p>
</form>
這是我的 php,其中包括重定向的標頭
<?php
if ( isset( $_FILES['pdfFile'] ) ) {
if ($_FILES['pdfFile']['type'] == "application/pdf") {
$source_file = $_FILES['pdfFile']['tmp_name'];
$dest_file = "upload/".$_FILES['pdfFile']['name'];
if (file_exists($dest_file)) {
print "The file name already exists!!";
}
else {
move_uploaded_file( $source_file, $dest_file )
or die ("Error!!");
if($_FILES['pdfFile']['error'] == 0) {
print "Pdf file uploaded successfully!";
print "<b><u>Details : </u></b><br/>";
print "File Name : ".$_FILES['pdfFile']['name']."<br.>"."<br/>";
print "File Size : ".$_FILES['pdfFile']['size']." bytes"."<br/>";
print "File location : upload/".$_FILES['pdfFile']['name']."<br/>";
header('Location: success.php');
}
}
}
else {
if ( $_FILES['pdfFile']['type'] != "application/pdf") {
print "Error occured while uploading file : ".$_FILES['pdfFile']['name']."<br/>";
print "Invalid file extension, should be pdf !!"."<br/>";
print "Error Code : ".$_FILES['pdfFile']['error']."<br/>";
}
}
}
?>
uj5u.com熱心網友回復:
請記住,必須在發送任何實際輸出之前呼叫 header(),無論是通過普通 HTML 標記、檔案中的空白行還是從 PHP 發送。
(來自 php.net) php 頭檔案
如果要使用輸出,請先使用 Javascript 或 Html 代碼
<meta http-equiv="refresh" content="2; URL=http://stackoverflow.com">
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/435916.html
