【问题标题】:SplFileInfo::getSize(): stat failed for C:\xampp\tmp\php88C2.tmpSplFileInfo::getSize(): C:\xampp\tmp\php88C2.tmp 的统计失败
【发布时间】:2020-01-20 18:49:06
【问题描述】:

当在 laravel 6 上上传图片时显示此错误

SplFileInfo::getSize(): C:\xampp\tmp\php88C2.tmp 的统计失败

我的代码

public function store(Request $request) {

        $this->validate($request,[
            "title"    => "required",
            "content"  => "required",
            "category_id"  => "required",
            "post_image" => "required|image",

        ]);

        $post_image = $request->post_image;
        $featured_new_name = time().$post_image->getClientOriginalName();
        $post_image->move('uploads/posts',$featured_new_name);

        $post = Post::create([
            "title"    => $request->title,
            "content"  => $request->content,
            "category_id"  => $request->category_id,
            "post_image" => 'uploads/posts/'.$featured_new_name,

        ]);


     return redirect()->back();
}

【问题讨论】:

标签: php laravel image upload


【解决方案1】:

我认为错误不是因为上传。它可能是在插入数据库时​​。尝试使用您在代码中使用的那些键检查表的列名

【讨论】:

    【解决方案2】:

    你配置了错误的文件名

     $post_image = $request->file('post_image');
     $featured_new_name = time().".".$post_image->getClientOriginalName();
     //File name will be like this '2568412.jpg/png/other'
    

    【讨论】:

      【解决方案3】:

      我最近遇到这个问题,实际上发现是插入数据库的问题。我已经更新了数据库并添加了图像列,但没有迁移数据库。迁移为我修复了它。给它检查一次。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-18
        • 2019-04-06
        • 2020-02-26
        • 2020-08-15
        • 1970-01-01
        • 2022-11-25
        • 2018-07-26
        • 2015-08-29
        相关资源
        最近更新 更多