我正在尝试构建我的第一个表单/文件上传器(我是一个新手)。
我正在我的Mac上的本地服务器上进行测试,表单,文件处理程序和uploads文件夹都在彼此相同的文件目录中。
当我使用提交表单选择文件时(测试文件为'testFilego.txt'且大小为3个字节'),我收到以下错误:http://localhost/PhP_exercises/__tizag/280-php-fileupload-test.php?MAX_FILE_SIZE=2500000&uploadedfile=testFilego.txt
。提交表单似乎没有连接到处理程序(?)。我以为测试文件会出现在我的uploads文件夹中。帮助
这是提交表格:
<form>
<form enctype="multipart/form-data" action="280-php-uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="2500000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</form>
这是表格应该联系的文件
<?php
280-php-uploader.php<?php
//This is '280-php-uploader.php'
// 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 . 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!";
}
?>
答案 0 :(得分:0)
正如Marco Acierno所说,我在表格中张贴了表格,这似乎导致了问题。