【问题标题】:Laravel, "getimagesize(asda.jpg): failed to open stream: No such file or directory"Laravel,“getimagesize(asda.jpg):无法打开流:没有这样的文件或目录”
【发布时间】:2019-06-21 18:48:28
【问题描述】:

伙计们,我正在尝试在 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): 无法打开流: 没有这样的文件或 目录”

这从未发生在我身上。我该怎么办?

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    您的 $file 可能是 Illuminate\Http\UploadedFile 的实例。 试试:

    list($width, $height) = getimagesize($file->path());
    

    【讨论】:

    • 它表示调用字符串上的成员函数 path()
    • 查看这篇文章:stackoverflow.com/questions/39846148/… 在每个步骤中使用 var_dump() 调试变量类型。
    • 确保表单的 enctype=multipart/form-data
    猜你喜欢
    • 2013-12-15
    • 2011-12-14
    • 1970-01-01
    • 2017-04-21
    • 1970-01-01
    • 2020-01-25
    • 1970-01-01
    • 2017-05-04
    相关资源
    最近更新 更多