使用 laravel 4.2 上传 Restful 文件,当文件太大时不起作用


Restful file upload with laravel 4.2, not working when file is too big

所以我已经坚持了一段时间,认为它可能会帮助其他遇到这种错误的人,也许你们这些天才可以帮助我更好地理解这一点。

我一直在尝试通过用户资源更新(PUT 方法)上传文件当文件太大时,我总是会收到"不允许 405 方法"错误,如果文件大小正确,我不会收到这种错误。PHP 工匠路线(有问题的行):

PUT user/{user} | user.update | UserController@update

即使尝试dd($_POST)或使用尝试和捕获,我也遇到了同样的错误。

'Symfony'Component'HttpKernel'Exception'NotFoundHttpException' in C:'wamp'www'dsada'bootstrap'compiled.php:5693

一旦移动到简单的帖子,一切都完美无缺。

我的函数代码:

  if($_POST==null)
        return Redirect::back()->with(['user' => $this->user, 'flash_bad' => 'too BIG']);
    try{
        if(Input::file('picture')==null)
            return Redirect::back()->with(['user' => $this->user, 'flash_bad' => 'must pick a picture']);
        $picture = Image::make(Input::file('picture'));
        $picture_size = $picture->filesize();
        $max_size_megabytes = 1;
        if($picture_size > $max_size_megabytes*1024*1024)
            return Redirect::back()->with(['user' => $this->user, 'flash_bad' => 'too big 2']);
    }catch (Exception $e){
        return Redirect::back()->with(['user' => $this->user, 'flash_bad' => 'wrong file type']);
    }

我认为它可以是 php.ini 中upload_max_filesize和post_max_size的值。像这样更改它,但使用您认为可以解决问题的大小:

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

更新后,您将需要重新启动服务。