Laravel PHP:上传大文件大小的图像会导致“getClientOriginalName()”为“null”


Laravel PHP: Uploading Image with Large file size results in 'getClientOriginalName()' being 'null'

我正在使用Laravel PHP,我有一个照片库,允许用户将图像上传到相册。 当我上传的图像时 正常文件大小 ,小于8MB,它们可以上传并保存到相册中就可以了。 但是,当我尝试上传大于 8MB 的图像时,我不断收到"在空时调用成员函数 getClientOriginalName()"错误

为了解释上传到照片库的大图像,我分别编辑了"nginx.conf"和"php.ini",以便"nginx.conf"中的前一行

client_max_body_size 8M; 

已更改为

client_max_body_size 25M;  

在"php.ini"中,这一行:

upload_max_filesize = 8M

已更改为:

upload_max_filesize = 25M

在这两个文件中进行更改后,我在 Putty 中运行:

sudo service nginx restart
sudo service php5-fpm restart

这是我上传新照片的控制器:

public function store()
{
    $input = 'Input::all();
    $validation = new Validators'Stone_Photo;
        $filename = str_random(4) . 'Input::file('photo_path')->getClientOriginalName();
        $destination = "uploads/photos/";
        $upload = 'Input::file('photo_path')->move($destination, $filename);
        if( $upload == false )
        {
            return 'Redirect::to('home.index')
            ->withInput()
            ->withErrors($validation->errors)
            ->with('message', 'Could not upload picture');
        }
        $this->stone_photo->create($input, $filename);
        return 'Redirect::route('show_stone', array('id' => $input['stone_id']));
}  

因此,再一次,8MB以下的照片仍然可以上传,但是当我尝试上传9MB或以上的照片时,我不断收到错误"调用成员函数getClientOriginalName()在null上"错误,我不知道为什么。 任何帮助将不胜感激。

由于您的控制器操作是store我猜您有一个 restfull 控制器,对于该操作,HTTP 方法是POST .如果是这种情况,您需要确保在php.ini中设置post_max_size

post_max_size = 25M

否则,对于任何POST请求,upload_max_filesize都将被 post_max_size 值(默认为 8MB)覆盖。

相关文章:
  • 没有找到相关文章