好的,所以我遵循了一个教程,该教程教我如何在我的网站上构建一个简单的上传系统。好吧,我收到了错误...
我有一个表单,允许用户选择他们要上传的文件:
<form enctype="multipart/form-data" action="studentAccess/files/uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
这个 PHP 脚本应该完成所有的工作。现在我对本教程有点困惑,我不确定这个脚本是否应该分成两个不同的文件,或者和现在一样在同一个文件中。
<?php
// Where the file is going to be placed
$target_path = "/studentAccess/uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$target_path = "/studentAccess/uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
上面的脚本放置在Files
studentAccess 内的文件夹中
我要存储上传文件的文件夹位于 studentAccess 中并调用uploads
studentAccess
|
| files
| |
| | uploader.php *this is where the script is located to upload file*
| |
| uploads
| |
| | *this is the folder where I want to store the uploaded files*
| |
以上是所有内容所在的文件夹布局。我包括这个的原因是因为我不确定它是否布局正确。文件是否uploader.php
需要与上传的文件存储在同一个文件夹中?
当我运行脚本(即使用表单上传文件并点击上传文件按钮)时,我收到三个直接显示在浏览器窗口中的错误。
Warning: move_uploaded_file(/studentAccess/uploads/NHSHandbook1314.doc) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/www/usd309bands.org/studentAccess/files/uploader.php on line 14
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpRpP6uz' to '/studentAccess/uploads/NHSHandbook1314.doc' in /home/www/usd309bands.org/studentAccess/files/uploader.php on line 14
最后是脚本本身生成的错误
There was an error uploading the file, please try again!
所以我真的不确定我做错了什么,在我看来,将上传的文件移动到上传文件夹时出现问题。但我真的不确定我需要做什么来解决这个问题。我确实检查并file_uploads
在我的服务器中打开。
我希望我已经详细描述了我的问题以获得帮助。我希望它以可读的格式排列。我真的需要一些帮助。