title: Upload image via ajax in Laravel 5
body: <p>I have a little problem with code.</p>
  
  <p>I can't receive input image in my controller. Then I use <code>print_r($input);</code> I receive empty array.</p>
  
  <p>My js code:</p>
  
  <pre><code>$(document).on('click', '#photo-upload #upload-button', function(e) {
      e.preventDefault();
  
      $.ajax({
  
          url: "/photo/upload/",
          data: new FormData($("#photo-upload")[0]),
          dataType:'json',
          type:'GET',
          processData: false,
          contentType: false,
  
          success: function ( data ) {
  
              alert("succes!");
          },
  
          error: function ( data ) {
  
              alert("error");
  
          }
      });
  });
  </code></pre>
  
  <p>my form:
              
                  </p>
  
  <pre><code>            &lt;div class="full-cell"&gt;
  
                  &lt;span&gt;Название&lt;/span&gt;
              &lt;/div&gt;
  
              &lt;div class="full-cell"&gt;
                  &lt;input type="text" name="name" class="input-full" id="name"&gt;
              &lt;/div&gt;
  
              &lt;div class="full-cell"&gt;
  
                  &lt;span&gt;Описание&lt;/span&gt;
              &lt;/div&gt;
  
              &lt;div class="full-cell"&gt;
                  &lt;textarea name="description" id="description" cols="30" rows="3"&gt;&lt;/textarea&gt;
              &lt;/div&gt;
  
              &lt;div class="full-cell"&gt;
  
                  &lt;span&gt;Загрузить в альбом:&lt;/span&gt;
  
                  &lt;select name="album" id="album"&gt;
  
                      @foreach ($albums as $album)
                          @include('partials.select._album_names')
                      @endforeach
                  &lt;/select&gt;
              &lt;/div&gt;
  
              &lt;div class="file"&gt;
  
                  &lt;input type="file" name="image" id="fileInput"/&gt;
              &lt;/div&gt;
  
              &lt;div class="window-footer"&gt;
  
                  &lt;button type="button" class="auth-button btn-sec" id="upload-cancel"&gt;Отмена&lt;/button&gt;
                  &lt;button type="submit" class="auth-button btn-advanced" id="upload-button" hidden=""&gt;Загрузить&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>My controller:</p>
  
  <pre><code>public function store(Request $request) {
  
      $user = Auth::user();                                                           //Данные учетной записи
      $input = Input::all();
      $image = Input::file('image');                                                  //Записываем картинку в переменную
  
      print_r($input);
  
      $filename  = $user-&gt;username . '.' . $image-&gt;getClientOriginalExtension();      //Создаем новое имя файла
  
      $date = date('Y-m-d');                                                          //Получаем дату
      $path = "user_data/photos/$date/";                                              //Создаем путь до оригинала
      $thumbnail_path = "user_data/photos/$date/thumbnail/";                          //Создаем путь до миниатюры
  
      File::makeDirectory("$path", 0775, true, true);                                 //Директория для фото
      File::makeDirectory("$thumbnail_path", 0775, true, true);                       //Директория для миниатюры
  
      $image-&gt;move($path, $filename);                                                 //Сохраняем картинку на сервер
  
  
      $photo = "$path" . $filename;                                                   //Адрес фото
      $thumbnail = "$thumbnail_path" . $filename;                                     //Адрес миниатюры
  
      File::copy($photo, $thumbnail);                                                 //копируюм фото в миниатюры
  
      $image = Image::make($thumbnail)-&gt;fit(153,90)-&gt;save();
  
      $new_photo = new Photo;
  
      $new_photo-&gt;owner_id    = $user-&gt;id;
      $new_photo-&gt;name        = $input['name'];
      $new_photo-&gt;description = $input['description'];
      $new_photo-&gt;photo       = "/$photo";
      $new_photo-&gt;thumbnail   = "/$thumbnail";
      $new_photo-&gt;album_id    = $input['album'];
  
      $new_photo-&gt;save();
  
  }   
  </code></pre>