2016-04-26 106 views
1

目前,我有下面的代碼,包含上傳表單爲什麼我的php腳本沒有在原始頁面中回顯結果?

<form enctype="multipart/form-data" action="uploader.php" method="POST"> 
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> 
Choose a file to upload: <input name="uploadedfile" type="file" /><br /> 
<input type="submit" value="Upload File" /> 

</form> 

<? include('uploader.php'); ?> 

我那麼有保存在同一目錄中的文件uploader.php的頁面。該文件包含以下代碼:

<?php 

if($_POST){ 
// Where the file is going to be placed 
$target_path = "uploads/"; 

/* Add the original filename to our target path. 
Result is "uploads/filename.extension" */ 
$target_path = $target_path .time() .basename($_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
    echo "The <a href=" . $target_path . ">file</a> has been uploaded"; 
} else{ 
    echo "There was an error uploading the file, please try again!"; 
} 

} 

?> 

我的目的是把它在同一頁上呼應"The <a href=" . $target_path . ">file</a> has been uploaded";,而是將其重定向到另一個頁面,顯示此消息。

這是怎麼發生的?

+4

它重定向對錶單操作使用 – 2016-04-26 09:40:26

+0

謝謝,龍的頁面。我刪除了表單動作位,現在它工作。 –

回答

0

你的表單動作設置爲uploader.php,所以所有事情都發生在那裏,所以當你點擊提交按鈕時,它會加載該文件並在該頁面上顯示你的回聲,這樣就不同於你開始的頁面。

3

嘗試: -

<form enctype="multipart/form-data" action="" method="POST"> 
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> 
    Choose a file to upload: <input name="uploadedfile" type="file" /><br /> 
    <input type="submit" value="Upload File" /> 

    </form> 
相關問題