mateooo
mateooo

Reputation: 145

Laravel and Dropzonejs, files are not uploaded correctly

I ham working on a project which involves file uploading. I am using DropzoneJS and Laravel for this project. Everything seems to work fine, i have included the js and css files correctly, also the form appears as in the example but the problem is the upload part! Droped files show the progress bar go to 100% but once reached it returns an error like this...

{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Call to a member function getClientOriginalName() on a non-object","file":"C:\\wamp\\www\\localsite\\app\\controllers\\AssetsController.php","line":121}}

I know that the upload process works ine becouse when i return var_dump(Input::file('file)); i get an array of the input data...

..but...

When i check for file like this Input::hasFile('photo') it seems that file is emty but it has an array form.

this is the Route

Route::post('create/album','AssetsController@album');

This is the Controller

public function album()
{

    $file = Input::file('file');

    $destinationPath = 'uploads';
    $filename = $file->getClientOriginalName();

    $uploadSuccsess = Input::file('file')->move($destinationPath, $filename);


       if( $uploadSuccsess ) {
         return Response::json('success', 200);
       } else {
         return Response::json('error', 400);
       }

}

This is the HTML

     <form action="http://localhost/create/album" enctype="multipart/form-data" id="post-form-dropzone" class="dropzone">
     </form>
<button type="submit" id="status-post-form-submit-btn" class="btn btn-sm btn-primary btn-post pull-right">Post</button>

This is the JS

Dropzone.options.PostFormDropzone = { // The camelized version of the ID of the form element

  acceptedFiles: "image/*", // Accept images only
  autoProcessQueue: false,
  uploadMultiple: true,
  parallelUploads: 100,
  maxFiles: 60,
  addRemoveLinks: true,

  // The setting up of the dropzone
  init: function() {
    var myDropzone = this;
    // First change the button to actually tell Dropzone to process the queue.
    $("#status-post-form-submit-btn").click(function(e) {

      e.preventDefault();
      e.stopPropagation();
      myDropzone.processQueue();
    });


  }

}

Ive been trying for hours but i cant seem to find the solution.

Thanks in advance.

Upvotes: 0

Views: 2940

Answers (1)

mateooo
mateooo

Reputation: 145

finally figured out how to fix this, this is what got it fixed this is my changed Controller

$file = Input::file('file');
    Image::make($file[0]->getRealPath())->resize(540, null, true)->save('assets/example.png');

If anyone is asking where did those image manipulation methods came from this is the class iam using http://intervention.olivervogel.net/image/getting_started/laravel

Hope this helps someone in the fututre

Upvotes: 3

Related Questions