2016-04-26 109 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> 
相关问题