我正在尝试在laravel中上传多个图像。
刀片:
<div class="col-lg-9 col-md-9 col-sm-12">
<input type="file" class="form-control m-input" name="event_images[]" multiple required >
</div>
控制器:
$images = $request->event_images;
if (is_array($images) || is_object($images)) {
foreach ($images as $file) {
list($width, $height) = getimagesize($file);
$extension = $file->getClientOriginalExtension();
$final_filename = $file->getFilename() . '.' . $extension;
Storage::disk('public')->put($final_filename, File::get($file));
$thumb_img_250 = Image::make($file->getRealPath())->resize(250, $new_height_250);
$thumb_img_250->save(storage_path('app/public/event_images/image_250') . '/' . $final_filename, 80);
$thumbs_real = Image::make($file->getRealPath());
$thumbs_real->save(storage_path('app/public/event_images/real_image') . '/' . $final_filename, 80);
$image = new EventImages();
$image->image = $file->getFilename() . '.' . $extension;
$image->save();
}
return redirect()->back()->with('success', sprintf('Images were sucessfully added'));
}
但是得到的是这个错误:
“ getimagesize(asda.jpg):无法打开流:没有此类文件或 目录”
这从未发生在我身上。我该怎么办?
答案 0 :(得分:1)
可能您的$ file是Illuminate \ Http \ UploadedFile的实例。 试试:
list($width, $height) = getimagesize($file->path());