Php 照亮\Http\Exceptions\PostTooLargeException无消息laravel 5.8
我的申请表中有一个post部分。 我想在上传视频时在我的帖子上添加视频此错误将发生 提示:我已经修改了php.ini,但是仍然有这个错误。如何解决这个错误我很感激任何建议,请帮助 立柱最大尺寸=1024MPhp 照亮\Http\Exceptions\PostTooLargeException无消息laravel 5.8,php,laravel,laravel-5.8,Php,Laravel,Laravel 5.8,我的申请表中有一个post部分。 我想在上传视频时在我的帖子上添加视频此错误将发生 提示:我已经修改了php.ini,但是仍然有这个错误。如何解决这个错误我很感激任何建议,请帮助 立柱最大尺寸=1024M 上载\u最大\u文件大小=1024M PostController.php <?php namespace App\Http\Controllers\Admin; use Illuminate\Http\Request; use App\Http\Controllers\Con
上载\u最大\u文件大小=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);
}
}
post_max_size
表示post正文中的大小,这意味着该大小是请求正文中包含的所有字段大小的聚合。因此post_max_size
必须大于upload_max_filesize
(添加所有上传的大小)+请求正文中其他字段中包含的数据
post_max_size
doc说:
设置允许的post数据的最大大小。此设置也会影响文件
上传。若要上载大文件,此值必须大于
上传最大文件大小
。一般来说,内存限制应该更大
小于post_max_size
请参阅详细信息。另请参阅。php artisan serve
使用php/cli
中的php.ini(通常在/etc/php[version]/cli
中)
相应地更新此文件:
post_max_size = 1024m
upload_max_filesize = 1024m
如果您使用的是Apache服务器,请尝试在php.ini中进行如下更改
立柱最大尺寸=1024m
upload_max_filesize=1024m您使用的是php artisan serve
?@ChristopherHubert是的,我使用的是php artisan serveIt,它说“不支持的图像类型。GD驱动程序只能解码JPG、PNG、GIF或WebP文件。”@Andria哦,这是另一个问题。这与请求正文负载无关。@Andria您应该为该问题提出另一个问题,并在那里清楚地描述该问题。如果我的回答符合您当前的问题,您应该将其标记为正确。
post_max_size = 1024m
upload_max_filesize = 1024m