【发布时间】:2016-08-20 01:03:33
【问题描述】:
我目前有以下代码,用于包含上传表单的页面
<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";,但它会重定向到另一个页面以显示此消息。
为什么会这样?
【问题讨论】:
-
它重定向到表单操作上使用的页面
-
谢谢小龙。我删除了表单操作位,现在它可以工作了。
标签: php html file-upload upload uploader