Illuminate \ Http \ Exceptions \ PostTooLargeException No message laravel 5.8

问题描述 投票:1回答:1

我在我的应用程序中有帖子部分.我想在我的帖子上添加视频,而它在上传视频时,会发生这个错误的提示.我已经修改了php.ini,但仍然有这个错误,如何解决这个错误,我感谢任何建议。我已经修改了php.ini,但仍然有这个错误如何解决这个错误,我很感激任何建议,请帮助!

post_max_size = 1024M upload_max_filesize = 1024M

PostController.php

   <?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Auth;
use DB;
use App\Post;
use App\Category;
use App\Subcategory;
use Image; 

class PostController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $page_name = 'Posts';   
        if (Auth::user()->type === 1 || Auth::user()->hasRole('Editor') || Auth::user()->hasRole('Master Admin')) { 
           $data = Post::with(['creator'])->orderBy('id','DESC')->get(); 
        }else{
            $data = Post::with(['creator'])->where('created_by', Auth::user()->id)->orderBy('id','DESC')->get();
        }
        return view('admin.post.list',compact('data','page_name'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
         $page_name = 'Create Post';
        $categories = Category::where('status',1)->select('name','id')->get(); 
        return view('admin.post.create',compact('page_name','categories'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request) //with this request we can pass the title , slug ... all fields
    {
        $this->validate($request,[
          'title'=>'required',
          'short_description'=>'required', 
          'description'=>'required', 
          'category_id'=>'required',
          'subcategory_id'=>'required',
          'img'=>'required',  
      ],[

        'title.required' => "The Title Field is Required",
        'short_description.required' => "The Short Description Field is Required",
        'description.required' => "The Description Field is Required",
        'img.required' => "The Image Field is Required",
        ]);

     $post = new Post();  // using Post Model to all the below fields can connect with Post Table in database
     $post->title = $request->title;
     $post->slug = str_slug($request->title,'-'); //title will be updated with this title name separated with -
     $post->short_description = $request->short_description;
     $post->description = $request->description;
     $post->category_id = $request->category_id;
     $post->subcategory_id = $request->subcategory_id;
     $post->status = 1;
     $post->hot_news = 0;
     $post->view_count = 0;
     $post->main_image = '';
     $post->thumb_image = '';
     $post->list_image = '';
     $post->created_by = Auth::id(); //who created this post brings by ID
     $post->save();
     $file = $request->file('img');
     $extension = $file->getClientOriginalExtension(); 
     $main_image = 'post_main_'.$post->id.'.'.$extension; 
     $thumb_image = 'post_thumb_'.$post->id.'.'.$extension; 
     $list_image = 'post_list_'.$post->id.'.'.$extension;
     Image::make($file)->resize(653,569)->save(public_path('/post/'.$main_image)); 
     Image::make($file)->resize(360,309)->save(public_path('/post/'.$list_image));
     Image::make($file)->resize(122,122)->save(public_path('/post/'.$thumb_image));
     $post->main_image = $main_image; 
     $post->thumb_image = $thumb_image;
     $post->list_image =  $list_image;
     $post->save();
     return redirect()->action('Admin\PostController@index')->with('success','Post Created Successfully');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $page_name = 'Edit Post';
        $post = Post::find($id);
        $categories = Category::where('status',1)->select('name','id')->get(); 
        return view('admin.post.edit',compact('page_name','post','categories'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
         $this->validate($request,[
          'title'=>'required',
          'short_description'=>'required', 
          'description'=>'required', 
          'category_id'=>'required',
          'subcategory_id'=>'required',

        ],[

        'title.required' => "The Title Field is Required",
        'short_description.required' => "The Short Description Field is Required",
        'description.required' => "The Description Field is Required",
        'img.required' => "The Image Field is Required",
        ]);

     $post = Post::find($id);
    if($request->file('img')){
        @unlink(public_path('/post/'.$post->$main_image)); 
        @unlink(public_path('/post/'.$post->$thumb_image));
        @unlink(public_path('/post/'.$post->$list_image));
        $file = $request->file('img');
     $extension = $file->getClientOriginalExtension();
     $main_image = 'post_main_'.$post->id.'.'.$extension;
     $thumb_image = 'post_thumb_'.$post->id.'.'.$extension;
     $list_image = 'post_list_'.$post->id.'.'.$extension; 
     Image::make($file)->resize(653,569)->save(public_path('/post/'.$main_image));
     Image::make($file)->resize(360,309)->save(public_path('/post/'.$list_image));
     Image::make($file)->resize(122,122)->save(public_path('/post/'.$thumb_image));
     $post->main_image = $main_image;
     $post->thumb_image = $thumb_image;
     $post->list_image =  $list_image;
   }
     $post->title = $request->title;
     $post->slug = str_slug($request->title,'-');
     $post->short_description = $request->short_description;
     $post->description = $request->description;
     $post->category_id = $request->category_id;
     $post->subcategory_id = $request->subcategory_id;
     $post->save();
     return redirect()->action('Admin\PostController@index')->with('success','Post Updated Successfully');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $post = Post::find($id);
        @unlink(public_path('/post/'.$post->$main_image));
        @unlink(public_path('/post/'.$post->$thumb_image));
        @unlink(public_path('/post/'.$post->$list_image));
        $post->delete();
        return redirect()->action('Admin\PostController@index')->with('success','Post Deleted Successfully');
    }



     public function status($id){
       $post = Post::find($id);
       if ($post->status === 1) {
            $post->status = 0;
        }else{
             $post->status = 1;
        }
          $post->save();
          return redirect()->action('Admin\PostController@index')->with('success','Post Status Changed Successfully');
    }


     public function hot_news($id){
       $post = Post::find($id);
       if ($post->hot_news === 1) { 
            $post->hot_news = 0;
        }else{
             $post->hot_news = 1;
        }
          $post->save();
          return redirect()->action('Admin\PostController@index')->with('success','Post Set As Hot News Changed Successfully');
    }


 public function subcategories()
    {

       $category_id = Input::get('category_id');
      $subcategories = Subcategory::where('category_id', '=', $category_id)->where('status',1)->get();
      return response()->json($subcategories);
    }

}

list.blade.php

  @extends('admin.layout.master')
  @section('content')


    <link rel="stylesheet" href="{{ asset('admin/assets/css/lib/datatable/dataTables.bootstrap.min.css ') }}">
    <!-- <link rel="stylesheet" href="assets/css/bootstrap-select.less"> -->





  <div class="breadcrumbs">
            <div class="col-sm-4">
                <div class="page-header float-left">
                    <div class="page-title">
                        <h1>{{ $page_name }}</h1>
                    </div>
                </div>
            </div>
            <div class="col-sm-8">
                <div class="page-header float-right">
                    <div class="page-title">
                        <ol class="breadcrumb text-right">
                            <li><a href="/back">Dashboard</a></li>

                            <li class="active">Posts</li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>

        <div class="content mt-3">
            <div class="animated fadeIn">
                <div class="row">

                <div class="col-md-12">
                    <div class="card">

                 @if($message = Session::get('success'))
                 <div class="alert alert-success">

                  {{ $message }}

                 </div>

                 @endif

                        <div class="card-header">
                            <strong class="card-title">{{ $page_name }}</strong>
     @permission(['Add Post','All'])              
 <a href="{{ url('/back/posts/create') }}" class="btn btn-primary pull-right">Create</a>            @endpermission

      @permission(['Add Post','All'])              
 <a href="{{ url('/back/comment') }}" class="btn btn-primary pull-right" style="margin-right: 5px;">All Comments</a>            @endpermission
                        </div>

                        <div class="card-body">
                  <table id="bootstrap-data-table" class="table table-striped table-bordered">
                    <thead>
                      <tr>
                        <th>#</th>
                        <th>Image</th>
                        <th>Title</th>
                        <th>Author</th>
                         <th>Total View</th>
                         <th>Status</th>
                         <th>Hot News</th>
                         <th>Options</th>
                      </tr>
                    </thead>
                    <tbody>

                      @foreach($data as $i=>$row)
                      <tr>
                        <td style="width: 5%; text-align:center;">{{ ++$i }}</td>
                        <td style="text-align:center;"> 
                 @if(file_exists(public_path('/post/').$row->thumb_image)) 
                 <img src="{{ asset('post') }}/{{ $row->thumb_image }} " class="img img-responsive"> 

                 @endif 
                        </td> 
                        <td  style="width: 13%; text-align:center; ">{{ $row->title }}</td>  

                        <td style="width: 5%; text-align:center;"> {{ $row->creator->name }} </td> <!-- use this method bring name in users table -->

                        <td style="width: 5%; text-align:center;">{{ $row->view_count }}</td>

                      <td style="width: 10%;"> 
                     {{ Form::open(['method'=>'PUT','url'=>['/back/post/status/'.$row->id],'style'=>'display:inline' ]) }}
                     @if($row->status === 1)
                       {{ Form::submit('Unpublish',['class'=>'btn btn-danger']) }}
                       @else
                       {{ Form::submit('Publish',['class'=>'btn btn-success']) }}
                     @endif
                       {{ Form::close() }}

                         </td>      

                        <td style="width: 5%"> 
                     {{ Form::open(['method'=>'PUT','url'=>['/back/post/hot/news/'.$row->id],'style'=>'display:inline' ]) }}
                     @if($row->hot_news === 1)
                       {{ Form::submit('No',['class'=>'btn btn-danger']) }}
                       @else
                       {{ Form::submit('Yes',['class'=>'btn btn-success']) }}
                     @endif
                       {{ Form::close() }}

                         </td>       


                        <td>
                          @permission(['Add Post','All','Post Update']) 
           <a href="{{ url('/back/comment/'.$row->id) }} " class="btn btn-info">Comment</a>  
             <a href="{{ url('/back/post/edit/'.$row->id) }} " class="btn btn-primary">Edit</a>
           @endpermission
           @permission(['Delete Post','All']) 
           {{ Form::open([
            'method'=>'DELETE',
            'url'=>['/back/post/delete/'.$row->id],
            'style'=>'display:inline',
            'onsubmit' => 'return confirmDelete()' 
             ]) }}
           {{ Form::submit('Delete',['class'=>'btn btn-danger']) }}
           {{ Form::close() }}
           @endpermission

                         </td>

                      </tr>
                      @endforeach
                    </tbody>
                  </table>
                        </div>
                    </div>
                </div>


                </div>
            </div><!-- .animated -->
        </div><!-- .content -->




    <script src="{{ asset('admin/assets/js/plugins.js') }} "></script>
    <script src="{{ asset('admin/assets/js/main.js') }}"></script>

<script src="{{ asset('admin/assets/js/lib/data-table/datatables.min.js') }} "></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/dataTables.bootstrap.min.js') }} "></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/dataTables.buttons.min.js') }} "></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/buttons.bootstrap.min.js') }}"></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/jszip.min.js') }}"></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/pdfmake.min.js') }} "></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/vfs_fonts.js') }} "></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/buttons.html5.min.js') }} "></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/buttons.print.min.js') }} "></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/buttons.colVis.min.js') }} "></script>
    <script src="{{ asset('admin/assets/js/lib/data-table/datatables-init.js') }} "></script>


    <script type="text/javascript">
        $(document).ready(function() {
          $('#bootstrap-data-table-export').DataTable();
        } );
    </script>




<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
    function confirmDelete(){

     var conform = confirm("Are You Sure To Delete?");
     if (conform)
       return true;
     else
       return false;
     }

</script>





@endsection

php laravel laravel-5.8
1个回答
1
投票

如果你使用的是Apache服务器,可以尝试在php.ini中做一些修改,比如说

post_max_size = 1024mupload_max_filesize = 1024m。


1
投票

post_max_size 代表post body中的大小,也就是说,这个大小是包含在请求体中的所有字段大小的集合。所以 post_max_size 必须大于 upload_max_filesize (加上所有上传的大小)+请求体中其他字段中包含的数据。

post_max_size doc说。

设置允许上传数据的最大大小。这个设置也会影响文件上传。要上传大文件,这个值必须大于 upload_max_filesize. 一般说来: memory_limit 应大于 post_max_size.

详见 此处. 参考 有效载荷过大 还。


1
投票

php artisan serve 使用来自 php/cli (通常在 /etc/php[version]/cli)

据此更新此文件。

post_max_size = 1024m
upload_max_filesize = 1024m
© www.soinside.com 2019 - 2024. All rights reserved.