我正在使用laravel。 img不会上传到我的public/imgs文件夹。它一直在说抱歉,上传文件时出现错误。无法将img上传到文件夹
// PHP CODE
$target_dir = "public/imgs/";
$target_file = $target_dir . basename($_FILES["img"]["name"]);
if (move_uploaded_file($_FILES["img"]["name"], $target_file)) {
echo "success";
}
else {
echo "Sorry, there was an error uploading your file.";
}
// HTML CODE
<form method="POST" action="/listings" enctype="multipart/form-data">
<input type="file" name="img">
</form>
尝试'回声'抱歉(上传失败)'。 $ _FILES ['img'] ['error'];'并参见这里的参考http://php.net/manual/en/features.file-upload.errors.php – vee
我认为你应该写完整的路径根路径(如:/ var/www/public/imgs)除非当然如果公开已经在根路径 –
@vee当我这样说时。对不起(上传失败)0 我试过已经jacky – Jeff99