如果图像成功保存在 laravel 上的文件夹中,如何制作文件夹缩略图?
How can I make folder thumb if image success saved in a folder on laravel?
我用laravel 5.6
我上传图片的方法是这样的:
public function uploadImage($file) {
if($file) {
$fileName = str_random(40) . '.' . $file->guessClientExtension();
}
$destinationPath = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'product';
if(!File::exists($destinationPath)) {
File::makeDirectory($destinationPath, 0755, true);
}
$file->move($destinationPath, $fileName);
return $fileName;
}
代码有效。如果方法运行,它会在产品文件夹
中保存一个文件
不过我想补充一个逻辑。如果图像成功保存在产品文件夹中,那么它将在文件夹产品中创建一个文件夹缩略图
我尝试在 $file->move($destinationPath, $fileName);
下面添加此代码,如下所示:
$destinationPathThumb = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'product' . DIRECTORY_SEPARATOR . 'thumb';
if(!File::exists($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$file->move($destinationPathThumb, $fileName)
然后我朗读我的方法,出现了这样的错误:
Parse error: syntax error, unexpected 'return' (T_RETURN)
看来代码行还是错的
我该如何解决这个问题?
你少了一个分号。
$destinationPathThumb = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'product' . DIRECTORY_SEPARATOR . 'thumb';
if(!File::exists($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$file->move($destinationPathThumb, $fileName);
你的IDE可以展示给你。
你错过了这一行旁边的分号
$file->move($destinationPathThumb, $fileName)
把这个
$file->move($destinationPathThumb, $fileName);
我用laravel 5.6
我上传图片的方法是这样的:
public function uploadImage($file) {
if($file) {
$fileName = str_random(40) . '.' . $file->guessClientExtension();
}
$destinationPath = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'product';
if(!File::exists($destinationPath)) {
File::makeDirectory($destinationPath, 0755, true);
}
$file->move($destinationPath, $fileName);
return $fileName;
}
代码有效。如果方法运行,它会在产品文件夹
中保存一个文件不过我想补充一个逻辑。如果图像成功保存在产品文件夹中,那么它将在文件夹产品中创建一个文件夹缩略图
我尝试在 $file->move($destinationPath, $fileName);
下面添加此代码,如下所示:
$destinationPathThumb = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'product' . DIRECTORY_SEPARATOR . 'thumb';
if(!File::exists($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$file->move($destinationPathThumb, $fileName)
然后我朗读我的方法,出现了这样的错误:
Parse error: syntax error, unexpected 'return' (T_RETURN)
看来代码行还是错的
我该如何解决这个问题?
你少了一个分号。
$destinationPathThumb = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'product' . DIRECTORY_SEPARATOR . 'thumb';
if(!File::exists($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$file->move($destinationPathThumb, $fileName);
你的IDE可以展示给你。
你错过了这一行旁边的分号
$file->move($destinationPathThumb, $fileName)
把这个
$file->move($destinationPathThumb, $fileName);