Reputation: 53
I have post section in my application . I want to add video on my post while it was uploading the video this error will occur Tips: I have modified php.ini but still having this error how to solve this error i appreciate any suggestion please help!
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
Upvotes: 2
Views: 7483
Reputation: 2951
php artisan serve
uses the php.ini from php/cli
(usually in /etc/php[version]/cli
)
Update this file accordingly:
post_max_size = 1024m
upload_max_filesize = 1024m
Upvotes: 5
Reputation: 77
If you are using Apache server just try to some changes in php.ini like this
post_max_size = 1024m upload_max_filesize = 1024m
Upvotes: 0
Reputation: 3941
post_max_size
represents the size that comes in the post body meaning the size is the aggregation of all fields' size containing in the request body. So post_max_size
must be greater than upload_max_filesize
(the addition of all uploads' size) + data containing in other fields in the request body.
post_max_size
doc says:
Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than
upload_max_filesize
. Generally speaking,memory_limit
should be larger thanpost_max_size
.
See in details here. Refer to Payload Too Large also.
Upvotes: 1