我正嘗試上傳帶有發佈請求的圖像並將其移至目錄。我試過..無法在目錄中寫入 - 數字海洋
$file = $request->file('file');
$extension = strtolower($file->getClientOriginalExtension());
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$generatedName = sha1(time().time());
$directory = '../public/uploads/imgs/'; // works
$fileName = $generatedName . "." . $extension; // works
// 1
$file->move($directory, $fileName);
// 2
$file->move(base_path().$directory, $fileName);
在這一點上,我收到錯誤:
1 Unable to write in the "../public/uploads/imgs" directory
2 Unable to write in the "var/www/laravel/public/uploads/imgs" directory
我以爲是權限引起的,但也沒有幫助。我試圖
sudo chmod 770 /var/www/laravel/public/uploads (also /imgs/
and
sudo chmod -R 775 /var/www/laravel/public/uploads
我還發現其他東西嘗試,但無法弄清楚用戶名位寫什麼:
sudo chown username:www-data /var/www/laravel/public/uploads/
我使用NGINX對數字海洋
仍然收到相同的錯誤..這似乎沒有幫助(1)和(2) – senty