Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

php - Small file get uploaded but not large file in Laravel

I have this action in controler

    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";
    }
  }
}

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";
      }

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Other answers refers saying only about the php.ini directiress.

I would like to give answer considering both php.ini and the Laravel Validation Rule

First check your php.ini

For the upload_max_filesize and post_max_size and change to your desired file size

upload_max_filesize = 100M
post_max_size = 100M

You shall have your rule like this

public static $updaterules = array(
    'uploadedimage' => 'image|max:5000'            
    );

Additional information :

You shall check for the file format for image by

'uploaded' => 'mimes:jpeg,bmp,png'

Read more about Laravel validation here

Update :

As the questioner didn't noticed which php.ini file is being used by the server. I am updating my answer accordingly so it might be useful for someone who has similar problems in future

To find the full configuration about the php.ini file which is currently being used by your server.

For Linux

php -i | grep php.ini

For Windows

php -i | find /i "Configuration File"

From a php file

i.e.,

<?php
phpinfo();
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...