我试图将图像放到文件夹中,而不是用时间戳生成。这给了我标题上的错误。
Intervention\Image\Exception\NotWritableException不能将图像数据写入路径(/Users/me/Sites/test/public/uploads/images/1573905600/title-1.jpg)
这是我的密码:
$photoPaths = $request->get('photo_paths');
if (isset($photoPaths)){
$photos = explode(';', $photoPaths);
$path = storage_path('tmp/uploads/');
$newPath = public_path('/uploads/images/').strtotime('12:00:00')."/";
$arrayPhoto = array();
foreach($photos as $photo){
$photoPath = $path . $photo;
if (File::exists($photoPath)) {
$newPhotoName = Str::slug($request->get('titre')."-".$i,"-").".jpg";
$newPhotoFullPath = $newPath . $newPhotoName;
$photo = Image::make($photoPath);
// $photo->resize(1400, 1050);
$photo->resize(null, 1050, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$photo->encode('jpg', 85);
if(!Storage::disk('public')->has($newPath)){
Storage::disk('public')->makeDirectory($newPath); //It seems it doesn't work
}
$saved = $photo->save($newPhotoFullPath); //Create the Exception
}
}
}我做错什么了?
谢谢
发布于 2019-11-16 14:57:59
检查此文件夹是否已创建。那就允许它写
sudo chmod -R 666 /public/upload/images //give permission your choice either it 666 or 775 or 777和
$newPath = public_path('/uploads/images/').strtotime('12:00:00')."/";
if (!file_exists($newPath)) {
mkdir($newPath, 0755);
}发布于 2019-11-16 14:48:53
查看这行代码$newPhotoName =Str::slug($request->get(‘titre’)。-“.$i,-”).“.jpg”;
它应该是$newPhotoName =Str::slug($request->get(‘title’).-“.$i,”-).“.jpg”;
我指的是$request->get('title')而不是$request->get('titre')。
或
您可以根据您的请求验证从刀片中签出您的输入名称,如果它们是相同的,也可以使用您的模型填充。
我希望这能帮到你。
https://stackoverflow.com/questions/58891527
复制相似问题