【发布时间】:2020-09-03 12:09:25
【问题描述】:
我一直在尝试在此站点上浏览以寻找答案,但对我没有任何作用,我想上传保存在 public_html 文件夹中的图像,而不是将其保存在项目文件夹中(我将项目文件夹分开并将所有public_html 文件夹中的公共文件)。已经绑定 public.path 但它返回到我的项目文件夹,而不是 public_html 一个。
我的图片上传控制器
public static function uploadSubmit($request, $type, $for)
{
if($request->hasFile('photos'))
{
$allowedfileExtension=['jpg','png'];
$files = $request->file('photos');
foreach($files as $file)
{
$extension = $file->getClientOriginalExtension();
$check=in_array($extension,$allowedfileExtension);
//dd($check);
if($check)
{
$idx = Image::create([
'type' => $type,
'ids' => $for,
'ext' => $extension,
])->id;
$filename = $idx . '.' . $file->getClientOriginalExtension();
$filename = $file->storeAs(public_path('images/'), $filename);
}
}
}
}
我已经在 public_html/index.php 中进行了这样的公共路径绑定
$app->bind('path.public', function() {
return __DIR__;
});
谢谢!
【问题讨论】: