我有这个PHP代码,它无法接受文件上传到服务器,他们告诉我未定义的索引文件,我该如何修复此错误,
$target_path = public_path().'/uploads';
// dd($target_path);
$target_path = $target_path . basename( $_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
echo "Upload and move success";
} else {
echo $target_path;
echo "There was an error uploading the file, please try again!";
}
?>
答案 0 :(得分:0)
$ _FILES数组中的一个或多个这些键未定义/未从表单传递:
['file']
['file']['name']
['file']['tmp_name']
您应该打印$ _FILES的值以确定哪个未定义:
print_r($_FILES);
然后将缺失的密钥追溯到您的输入表单。也许这是形式上的拼写错误。