我正在使用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