用laravel做图片上传的时候,图片大于2m的时候就上传失败

PHP和nginx的配置都修改了,都是允许50M的文件上传
但是依旧报这个错误

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
No message

form表单的属性

<form class="form-horizontal form-material" id="login" enctype="multipart/form-data" method="post" action="{{ url('/certify') }}">

表单的按钮处也有csrf

<div class="form-group text-center m-t-20" style="clear: both;">
     <div class="col-xs-10" style="margin-top: 15px">
          <button class="btn btn-info btn-lg btn-block text-uppercase waves-effect waves-light" type="submit">申请</button>
              {{ csrf_field() }}
      </div>
</div>

路由的定义

Route::post('/certify', 'LoginController@loginCertify');
阅读 2.8k
2 个回答

不应该是这个错吧?
你小于2M的能传?
当前这个错是因为请求方法不正确,比如定义的POST,你用GET去请求


主要需要改的配置
php中 post_max_size, upload_max_filesize
nginx中 client_max_body_size
改后需要重启

赞同楼上的说法, 怀疑你报错信息贴的不正确, MethodNotAllowedHttpException用来判断请求的METHOD, 跟上传文件大小没有关系, laravel源码如下

MethodNotAllowedHttpException

// file vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php 221-252
/**
 * Get a route (if necessary) that responds when other available methods are present.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  array  $methods
 * @return \Illuminate\Routing\Route
 *
 * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
 */
protected function getRouteForMethods($request, array $methods)
{
    if ($request->method() == 'OPTIONS') {
        return (new Route('OPTIONS', $request->path(), function () use ($methods) {
            return new Response('', 200, ['Allow' => implode(',', $methods)]);
        }))->bind($request);
    }

    $this->methodNotAllowed($methods);
}

/**
 * Throw a method not allowed HTTP exception.
 *
 * @param  array  $others
 * @return void
 *
 * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
 */
protected function methodNotAllowed(array $others)
{
    throw new MethodNotAllowedHttpException($others);
}
// file vendor/symfony/http-kernel/Exception/MethodNotAllowedHttpException.php 12-31
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\HttpKernel\Exception;

/**
 * @author Kris Wallsmith <kris@symfony.com>
 */
class MethodNotAllowedHttpException extends HttpException
{
    /**
     * @param array      $allow    An array of allowed methods
     * @param string     $message  The internal exception message
     * @param \Exception $previous The previous exception
     * @param int        $code     The internal exception code
     */
    public function __construct(array $allow, $message = null, \Exception $previous = null, $code = 0)
    {
        $headers = array('Allow' => strtoupper(implode(', ', $allow)));

        parent::__construct(405, $message, $previous, $headers, $code);
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题