鍍金池/ 問答/PHP  Linux/ 用laravel做圖片上傳的時(shí)候,圖片大于2m的時(shí)候就上傳失敗

用laravel做圖片上傳的時(shí)候,圖片大于2m的時(shí)候就上傳失敗

PHP和nginx的配置都修改了,都是允許50M的文件上傳
但是依舊報(bào)這個(gè)錯(cuò)誤

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">申請(qǐng)</button>
              {{ csrf_field() }}
      </div>
</div>

路由的定義

Route::post('/certify', 'LoginController@loginCertify');
回答
編輯回答
涼薄

不應(yīng)該是這個(gè)錯(cuò)吧?
你小于2M的能傳?
當(dāng)前這個(gè)錯(cuò)是因?yàn)檎?qǐng)求方法不正確,比如定義的POST,你用GET去請(qǐng)求


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

2017年8月28日 09:46
編輯回答
情已空

贊同樓上的說法, 懷疑你報(bào)錯(cuò)信息貼的不正確, MethodNotAllowedHttpException用來判斷請(qǐng)求的METHOD, 跟上傳文件大小沒有關(guān)系, 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);
    }
}
2018年7月6日 02:38