[英]Laravel League\Flysystem\Exception: Impossible to create the root directory
[英]Laravel Impossible to Create Root Directory
我已經查看了關於此的其他帖子,出於某種原因我的似乎是獨一無二的
基本上我想做的是將上傳的照片存儲在公共目錄中以便於訪問,但是當我存儲它們時我試圖將它們存儲在用戶特定的文件夾中,所以
/public/photos/$User->id/$filename.jpg
現在我有 Dropzone 上傳文件,我已經添加到我的文件系統。php 這個聲明
'public_uploads' => [
'driver' => 'local',
'root' => public_path(),
],
所以理論上當我訪問它時使用
Storage::disk('public_uploads')
它應該檢索正確的路徑
這也是我的 controller
$User = User::find(Auth::user()->id);
$Photo = Request::file('photo');
Storage::disk('public_uploads')->put("photos/$User->id", $Photo);
然后我在上傳時從 Laravel 收到此錯誤
{message: "Impossible to create the root directory "/censoredfilesystem/public/Photos/1".",…}
不知道這段時間是從哪里來的,非常感謝您的幫助
謝謝大家!
根據評論設置權限不知不覺地修復了它,我用過
chown -R www-data:root .
在我的目錄的根目錄中
編輯:我使用的www-data:root
,意思是設置Laravel目錄內一切的所有者www-data
(Web服務器)和root
是root
明顯。 如果您這樣做,您應該使用非 root 用戶或僅使用www-data
只需先創建在 filesystems.php 配置文件中設置的文件夾。 它們需要在那里,否則系統會嘗試創建它們。
另一種選擇是將 go 輸入 /storage/app/public/ 並創建要在其中存儲文件的文件夾(如果不存在)即 /storage/app/public/ addfolder (如果管理員或在服務器上工作)
首先,刪除這些文件夾
/public/storage
/storage/app/public
然后運行以下命令
php artisan storage:link
if(($request->hasfile('customer_doc'))){
foreach($request->file('customer_doc') as $file)
{
$input['customer_id'] = $lastinsertedid;
// Get filename with the extension
$filenameWithExt = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
// Get just ext
$extension = $file->getClientOriginalExtension();
// Filename to store
$fileNameToStore = $filename . '_' . time() . '.' . $extension;
// Upload Image
$file->storeAs('public/Customer/docs', $fileNameToStore);
$input['customer_doc'] = $fileNameToStore;
$input['add_by']= $add_by;
CusDoc::create($input);
}
}
在 Centos 和 nginx 中:
sudo chown -R nginx:root public/duck/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.