简体   繁体   中英

I'm getting this error in laravel SplFileInfo::getSize() when I try to save the data in database

public function store(Request $request)
    {
        $this->validate($request , [

            'title'=> 'required|max:200',
            'featured' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
            'content' => 'required',
            'category_id' => 'required',
        ]);
        // dd(ini_get('upload_max_filesize'));

        $featured = $request->featured;

        $featured_new_name = time().$featured->getClientOriginalName();

        $featured->move('uploads/posts' , $featured_new_name);

        $post = Post::create([
            'title' => $request->title,
            'content' => $request->content,
            'category_id' => $request->category_id,
            'featured' => 'uploads/posts'. $featured_new_name
        ]);

        return redirect()->back();


    } 

My max_upload_size = 2g and max_file_uploads = 20. I still get this error. It was working fine before I got to sleep But when I checked again This error appeared.

You probably forgot to set the post_max_size in your php.ini to 2g also. Don't forget to restart your apache/web server after making php.ini changes.

My php.ini was fine everything was ok with php.ini . I had a Column in my database slug . It was not null by default and I was not inserting a slug into it. When I changed it to Null and submitted it again it started working.

If your php.ini file is fine then check your Database table in which you are uploading the file path. If you have a column in which you are not saving a value and it is not Null by default then change it to Null .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM