<?php
$target_path1 = "uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path1 = $target_path1 . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path1))
{
echo "The first file ". basename( $_FILES['uploaded_file']['name'])."has been uploaded.";
} else {
echo "There was an error uploading the file, please try again!";
echo "filename: " . basename( $_FILES['uploaded_file']['name']);
echo "target_path: " .$target_path1;
}
?>
这有3个错误
注意:第5行的D:\ anddev \ project \ web \ upload_test \ upload_media_test.php中的未定义索引:uploaded_file
注意:第6行的D:\ anddev \ project \ web \ upload_test \ upload_media_test.php中的未定义索引:uploaded_file
注意:第11行的D:\ anddev \ project \ web \ upload_test \ upload_media_test.php中的未定义索引:uploaded_file
如何修复此代码?
答案 0 :(得分:0)
放:
<?php
var_dump($_FILES);
exit;
只是在文件的开头,检查那里有什么。你的数组中有错误的键。检查输入文件的正确键是什么。
答案 1 :(得分:0)
始终添加检查以确保您确实获得了某些内容,
您可以使用is_uploaded_file试试这样:
<?php
if(is_uploaded_file($_FILES['uploaded_file']['tmp_name']){
//we got something, set it up
$target_path1 = "uploads/";
$file = basename( $_FILES['uploaded_file']['name']);
$full_path = $target_path1.$file;
//perform the upload
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $full_path)) {
echo "The first file ".$file." has been uploaded.";
} else {
echo "There was an error uploading the file, please try again!";
echo "filename: " . $file;
}
}else{
echo "Nothing was uploaded";
}
?>