在Laravel中上传小文件但不上传大文件 [英] Small file get uploaded but not large file in Laravel

查看:56
本文介绍了在Laravel中上传小文件但不上传大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制器中有此操作

    public function upload() {
  // getting all of the post data
  $file = array('image' => Input::file('image'));
  //return $file;
  // setting up rules
  $rules = array('image' => 'required'); //mimes:jpeg,bmp,png and for max size max:10000
  // doing the validation, passing post data, rules and the messages
  $validator = Validator::make($file, $rules);
  if ($validator->fails()) {
    // send back to the page with the input data and errors
   // return Redirect::to('upload')->withInput()->withErrors($validator);
   return "error validation";
  }
  else {
    // checking file is valid.
    if (Input::file('image')->isValid()) {
      $destinationPath = 'myuploads'; // upload path
      $extension = Input::file('image')->getClientOriginalExtension(); // getting image extension
      $fileName = Input::file('image')->getClientOriginalName();
     // $fileName = rand(11111,99999).'.'.$extension; // renameing image
      Input::file('image')->move($destinationPath, $fileName); // uploading file to given path

      return "upload success";
    }
    else {
      // sending back with error message.
      Session::flash('error', 'uploaded file is not valid');
      return "error";
    }
  }
}

它适用于2MB的小文件,但不适用于4MB的文件. 如果大于或等于4MB,则会在验证时出错.在上面的代码中,有以下代码

It works for small file size like 2MB but won't work for 4MB file size. For 4MB or more it gets error in validation.In the code above there's this code

 if ($validator->fails()) {

       return "error validation";
      }

它给出此自定义错误error validation.我已经在配置php.ini的最大上传限制和发布限制.

It gives this custom error error validation. I have already worked on configuring php.ini for max upload limit and post limit.

推荐答案

好吧,我找到了答案,上面提到的在php.ini中更改upload_max_filesizepost_max_size的内容实际上是解决该问题的唯一方法.问题提到的问题.

Well I found the answer, The things mentioned above to make change in php.ini about upload_max_filesize and post_max_size are infact the only thing to solve the problem mentioned by the question.

唯一的问题是我正在使用wamp,显然wamp在php文件夹中有多个php.ini文件,在apache文件夹中有一个.我应该在apache文件夹中进行更改时,在PHP文件夹中进行了更改.

The only problem was that I am using wamp and apparently wamp has multiple php.ini files one in php folder and one in apache folder. I made changes in PHP folder when the change should be made to the one inside apache folder.

这篇关于在Laravel中上传小文件但不上传大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆