【问题标题】:How to Fix PostTooLargeException when file uploading?文件上传时如何修复 PostTooLargeException?
【发布时间】:2020-10-22 19:12:19
【问题描述】:

我是 laravel 的新手。 这是我的问题。当我尝试上传大文件时,页面抛出 PostTooLargeException。我想要解决方案,当用户上传照片时,我想在文件输入字段下显示自定义错误消息。 ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ......

我的控制器代码

protected function edituserdata(Request $request)
    {
        $this->validate($request, [
        'name' => 'required',
        'email' => 'required|email'
        ]);

        $data = $request->all();
        $id=$data['id'];
        $input['email'] = Input::get('email');
        $input['name'] = Input::get('name');

        $rules = array(
        'email'=>'required|email|unique:users,email,'.$id,
        'name' => 'required|regex:/^[\w-]*$/|max:255|unique:users,name,'.$id,
        'photo' => 'max:1024|mimes:jpg,jpeg,png'
        );

        $messages = array(
        'email' => 'The :attribute field is already exists',
        'name' => 'The :attribute field must only be letters and numbers (no spaces)'
        );

        $validator = Validator::make(Input::all(), $rules, $messages);

        if ($validator->fails())
        {
            $failedRules = $validator->failed();
            return back()->withErrors($validator);
        }
        else
        { 
            $name=$data['name'];
            $email=$data['email'];
            $password=bcrypt($data['password']);
            $phone=$data['phone'];
            $currentphoto=$data['currentphoto'];
            $image = Input::file('photo');

        if($image!="")
        {   
            $userphoto="/userphoto/";
            $delpath = base_path('images'.$userphoto.$currentphoto);
            File::delete($delpath); 
            $filename  = time() . '.' . $image->getClientOriginalExtension();
            $path = base_path('images'.$userphoto.$filename);
            Image::make($image->getRealPath())->resize(200, 200)->save($path);
            $savefname=$filename;
        }
        else
        {
            $savefname=$currentphoto;
        }       

        if($data['password']!="")
        {
            $passtxt=$password;
        }
        else
        {
            $passtxt=$data['savepassword'];
        }

        $admin=$data['usertype'];
        if(!empty($data['gender']))
        {
            $gender = $data['gender'];
        }
        else
        {
            $gender = "";
        }

        DB::update('update users set name="'.$name.'",email="'.$email.'",password="'.$passtxt.'",phone="'.$phone.'",photo="'.$savefname.'",admin="'.$admin.'",gender="'.$gender.'" where id = ?', [$id]);

        DB::update('update shop set seller_email="'.$email.'" where user_id = ?', [$id]);
        
        return back()->with('success', 'Account has been updated');
        }
    }

【问题讨论】:

标签: php html css laravel


【解决方案1】:

您上传的文件大于您的 php.ini 文件允许的大小。您所要做的就是将 php.ini 文件中的post_max_size 设置为更大的值(例如 50mb)

PostTooLargeException 不是 Laravel 错误,它来自你的PHP

您可以在php.ini 文件中检查以下参数,例如:

upload_max_filesize = 40m
post_max_size = 50m

像 (apache) 一样重启服务器后

希望这对你有用!

【讨论】:

猜你喜欢
  • 2018-08-30
  • 1970-01-01
  • 2018-02-03
  • 1970-01-01
  • 2015-03-24
  • 1970-01-01
  • 1970-01-01
  • 2021-06-16
  • 2012-04-30
相关资源
最近更新 更多