2

i have an upload form in laravel 5 and i want to send a file more than 2M and i change php.ini for max upload size and post size but it doesent work too!! when my csrf is enable i get csrf token mismatch and when i disable it after sending all of fields in form send to controller empty!! my view :

<div class="col-lg-6" style="float:right">
{!! Form::open(array('url'=>'admin/uploadtmp','method'=>'POST', 'files'=>true)) !!}


                            <div class="form-group col-md-12 pull-right">

                                 {!! Form::text('title', Input::old('title'), array('class' => 'form-control', 'placeholder' => 'نام قالب')) !!}

                                    <div style="color:red">
                                        {!!$errors->first('title')!!}
                                    </div>
                            </div>

                            <div class="form-group col-md-12">
                                {!! Form::textarea('description', Input::old('description'), array('class' => 'form-control', 'rows' =>'8', 'placeholder' => 'توضیحات')) !!}

                                <div style="color:red">
                                        {!!$errors->first('description')!!}
                                    </div>
                            </div>
                            <div class="form-group col-md-6" style="float:right">

                                <select name="brandid" class="form-control" placeholder="برند قالب">
                                    <option value="">برند قالب خود را انتخاب کنید</option>
                                    @foreach($brands as $brand)
                                    <option value="{{$brand->id}} ">{{$brand->title}} </option>
                                    @endforeach
                                  </select>
                            </div>
                            <div class="form-group col-md-6" style="float:right">
                               <select name="categoryid" class="form-control">
                                    <option value="">دسته بندی قالب خود را انتخاب کنید</option>
                                    @foreach($categories as $category)
                                    <option value="{{$category->id}} ">{{$category->title}} </option>
                                    @endforeach
                                  </select>
                            </div>
                            </div> 

                            <div class="form-group col-md-6">
                                <div class="form-group">
                                     {!! Form::label('لطفا فایل قالب خود را به صورت زیپ شده از طریق دکمه ی زیر انتخاب کنید') !!}    
                                     {!! Form::file('zip' , Input::old('zip')) !!}
                                     <div style="color:red">
                                        {!!$errors->first('zip')!!}
                                    </div>
                                </div>
                                <div class="form-group">
                                     {!! Form::label('لطفا فایل اسکرین شات قالب خود را با فرمت jpg و حجم کمتر از پنجاه کیلوبایت از طریق دکمه ی زیر انتخاب کنید') !!}
                                     {!! Form::file('image') !!}
                                     <div style="color:red">
                                        {!!$errors->first('image')!!}
                                    </div>
                                </div>

                                <input type="submit" name="submit" class="btn btn-primary pull-left" value="ارسال" >


                        {!! Form::close() !!}

                        @if(Session::has('error'))
                            <div class="col col-lg-12 alert alert-success alert-dismissable"> 
                                <button style="float:left" type="button" class="close" data-dismiss="alert" aria-hidden="true">&times; </button>
                                    {!! Session::get('error') !!}
                            </div>
                        @endif
                        @if(Session::has('success'))
                            <div class="col col-lg-12 alert alert-success alert-dismissable"> 
                                <button style="float:left" type="button" class="close" data-dismiss="alert" aria-hidden="true"> &times; </button> 
                                    {!! Session::get('success') !!}
                            </div>
                        @endif
                        </div>
              </div>

my controller:

class TemplateController extends Controller
{
    public function newtemplate(){
        // getting all of the post data
        $files = array(
          'zip'   => Input::file('zip'),
          'image' => Input::file('image'),
          'title' => Input::input('title'),
          'description' => Input::input('description'),
          'brandid' =>Input::input('brandid'),
          'categoryid' =>Input::input('categoryid'),
          );
        $rules = array(
          'image' => 'mimes:jpeg,jpg | max:5000 | required',
          'zip'   => 'mimes:zip,rar | max:40000 | required',
          'title'   => 'required',
          'description'   => 'required',
          ); //mimes:jpeg,bmp,png and for max size max:10000
         $messages =[

              'image.mimes' => 'فرمت فایل ارسالی شما صحیح نمی باشد',
              'image.max' => 'حداکثر اندازه ی فایل ارسالی شما باید 50 کیلو بایت باشد',
              'zip.mimes' => 'فرمت فایل ارسالی شما باید حتما zip باشد',
              'required' => 'این فیلد نباید خالی باشد'
          ];
          $validator = Validator::make($files, $rules,$messages);
          if ($validator->fails()) {
            // send back to the page with the input data and errors
            return Redirect::to('admin/templates')->withInput()->withErrors($validator);
          }
          else{
                if (Input::file('zip')->isValid() && Input::file('image')->isValid()) {


                      $template = new Template;
                      $template->creator_id = Auth::user()->id;
                      $template->title = Input::input('title');
                      $template->description = Input::input('description');
                      $template->category_id = Input::input('categoryid');
                      $template->brand_id = Input::input('brandid');
                      $template->save();

                      $lastid = $template->id;

                      //$destinationPath = 'uploads'; // upload path
                      $extension = Input::file('zip')->getClientOriginalExtension(); // getting image extension
                      $extension2 = Input::file('image')->getClientOriginalExtension(); // getting image extension
                      $filename = $lastid.'.'.$extension; // renameing image
                      $filename2 = $lastid.'.'.$extension2; // renameing image

                      //Storage::disk('local')->put('screenshots/'.$filename, Input::file('image'));
                      Input::file('zip')->move(storage_path().'/zipfiles', $filename);
                      Input::file('image')->move(storage_path().'/screenshots', $filename2);
                      //Storage::disk('local')->put('zipfiles/'.$filename2,Input::file('zip'));
                      // sending back with message
                      Session::flash('success', 'عملیات با موفقیت صورت گرفت'); 
                      return Redirect::back();

              }

               else {
                  // sending back with error message.
                  Session::flash('error', 'مشکل در آپلود فایل ها');
                  return Redirect::back();
                }
            }
       }
}
user1603666
  • 21
  • 1
  • 3
  • are you sending your data with an ajax call? – Franco Dec 08 '15 at 18:14
  • Did you restart apache/your web server after changing php.ini settings? – Tim Lewis Dec 08 '15 at 18:26
  • Are you using Apache or Nginx? – Alex Dec 08 '15 at 18:28
  • i am using wamp server on win 7 , yes i restart that after change! i send data with a form with post method and i am not using ajax, its worked true for files with size less than 2M !!! – user1603666 Dec 08 '15 at 19:23
  • i wonder, it looks like server problem. to be sure, try to make a dummy php script to dump your input like, `` in some other directory, then pass your form to it. also, if possible - to clarify, can we look at your `upload_max_filesize` and `post_max_size`? – Bagus Tesa Dec 08 '15 at 21:52
  • upload_max_filesize = 40M post_max_size = 40M max_execution_time = 500 – user1603666 Dec 09 '15 at 05:37

2 Answers2

2

First of all are you running application via command php artisan serve?

if yes then your php.ini file should be modified from /etc/php-<version>/cli/ instead of /etc/php-<version>/apache/. because this command run from cli so it uses its own php configuration.

so open with gedit or sublime whatever you love. and change upload_max_filesize and post_max_size and memory_limit

memory_limit = 1024M
upload_max_filesize = 512M
post_max_size = 512M

then restart via service apache2 restart.

0

You need to change the upload_max_filesize and post_max_size in the php.ini configuration, the location of the config depends on your environment, but you can put a Loaded Configuration File variable contains the full path to the ini, then you change

upload_max_filesize = 50M
post_max_size = 50M

Finally restart apache and voilà

You can see this question for more details, this is not laravel issue, but php configuration

Community
  • 1
  • 1
kEpEx
  • 830
  • 11
  • 20
  • in my question i said that change this atributes but it dosent work with laravel yet !! – user1603666 Dec 09 '15 at 05:40
  • increase the value of memory_limit too, ideally make it more than 50M. Also, check these values using phpinfo function to verify if your changes are being read by apache or not. – Vikas Dec 09 '15 at 07:05
  • my memory_limit is 120M , i checked all in phpinfo all of them is true but until something is wrong! – user1603666 Dec 09 '15 at 18:30
  • @user1603666 have you run via `php artisan serve` ?? change **php.ini** from `/etc/php-/cli/` instead of `/etc/php-/apache/` – MD Alauddin Al-Amin Nov 28 '19 at 05:45