Laravel 存储上传图片和文件
Laravel storage upload Image and File
我正在尝试将来自我的请求的图像保存在我的存储中,但发生了一些奇怪的事情:我有以下代码
$ request-> file ('UploadIMG') -> store ('public'. '/'. 'clients');
执行时会将图像保存在以下位置
storage \ app \ public \ clients \ dUpBTL0V25h2Q1825IUmvvIZhcwVPixLaVDdItuG.jpg
我想改变这个值并设置一个名字,所以我使用了下面的代码
Storage :: disk ('local') -> put ('clients'.'/'.$ fileName, $Image, 'public');
当我 运行 它创建的存储
时,假设我的 $ fileName 的值为 01.jpg
storage \ app \ clients \ 01.jpg \ dUpBTL0V25h2Q1825IUmvvIZhcwVPixLaVDdItuG.jpg
它最终创建了一个带有图像名称的文件夹并放置了带有随机名称的图像,我如何为我的图像取一个名字?
您可以使用storeAs()
方法保存上传的文件并命名为:
$request->file('UploadIMG')->storeAs('public/clients', $fileName);
$file = $request->file('pic');
$picName = $file->getClientOriginalName();
$imagePath = '/public/clients';
$file->move(public_path($imagePath), $picName);
我正在尝试将来自我的请求的图像保存在我的存储中,但发生了一些奇怪的事情:我有以下代码
$ request-> file ('UploadIMG') -> store ('public'. '/'. 'clients');
执行时会将图像保存在以下位置
storage \ app \ public \ clients \ dUpBTL0V25h2Q1825IUmvvIZhcwVPixLaVDdItuG.jpg
我想改变这个值并设置一个名字,所以我使用了下面的代码
Storage :: disk ('local') -> put ('clients'.'/'.$ fileName, $Image, 'public');
当我 运行 它创建的存储
时,假设我的 $ fileName 的值为 01.jpgstorage \ app \ clients \ 01.jpg \ dUpBTL0V25h2Q1825IUmvvIZhcwVPixLaVDdItuG.jpg
它最终创建了一个带有图像名称的文件夹并放置了带有随机名称的图像,我如何为我的图像取一个名字?
您可以使用storeAs()
方法保存上传的文件并命名为:
$request->file('UploadIMG')->storeAs('public/clients', $fileName);
$file = $request->file('pic');
$picName = $file->getClientOriginalName();
$imagePath = '/public/clients';
$file->move(public_path($imagePath), $picName);