我如何在Laravel-6中更新多个图像?

我要更新laravel中的多个图像,当我要更新laravel中的新图像时,以前的图像应从文件夹中自动删除。 这是我的图片更新代码...

$thumbDirPath = date("Ymd").'/thumb/'.$chr;
$smallDirPath = date("Ymd").'/small/'.$chr;

if($r->hasFile('propertyImages')){
$propImage = [];
for ($v=0; $v < count($r->propertyImages); $v++) {
    $thums      = $r->propertyImages;
    $filnameSmall = 'small-'.uniqid($chr).'-'.$v.'.'.$thums[$v]->getclientOriginalExtension();
    $img = Image::make($thums[$v]->getRealPath());
    $img->resize(300,null,function ($constraint) {
        $constraint->aspectRatio();
    });
    $smallPath = public_path().'/'.$type.'/'.date("Ymd").'/small'.'/'.$chr.'/'.$filnameSmall;
    if (file_exists($smallPath)) {
     $this->removeImage($smallPath);
 }
 $img->save($smallPath);

 $optimizerChain = OptimizerChainFactory::create();
 $optimizerChain->optimize($smallPath);

 $filnameLarge = 'thumb-'.uniqid($chr).'-'.$v.'.'.$thums[$v]->getclientOriginalExtension();
 $img = Image::make($thums[$v]->getRealPath());
 $img->resize(1080,function ($constraint) {
    $constraint->aspectRatio();
});
 $thumbPath = public_path().'/'.$type.'/'.date("Ymd").'/thumb'.'/'.$chr.'/'.$filnameLarge;

 if (file_exists($thumbPath)) {
    $this->removeImage($thumbPath);
}
$img->save($thumbPath);
$optimizerChain->optimize($thumbPath);

$propImage[$v]['small'] = $filnameSmall;
$propImage[$v]['smallDirPath'] = $smallDirPath;
$propImage[$v]['large'] = $filnameLarge;
$propImage[$v]['thumbDirPath'] = $thumbDirPath;
}
}else{
$propImage = NULL;
}
lhp1231 回答:我如何在Laravel-6中更新多个图像?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3139359.html

大家都在问