Malta Origo
Malta Origo

Reputation: 45

Error with POST ajax during image upload with dropzone

I have a form,where I included the dropzone.js. The plugin its working till preview image,after I get a POST error:500 (Internal Server Error) on dropzone.js:1386

Dropzone.prototype.submitRequest = function(xhr, formData, files) {
      return xhr.send(formData);<--here
    }; 

My view:

Dropzone.options.images = false;
	$("#images").dropzone({ 
 	url: "{{url('/')}}/ajax-uploadvehicleimage",
 	paramName: "file",
 	maxFiles: 10,
    maxfilesexceeded: function(file) {
        this.removeFile(file);
       	alert('you no have more picture avaible! Pay for more here');
    },
     error: function(file, response) {
        if($.type(response) === "string")
            var message = response; //dropzone sends it's own error messages in string
        else
            var message = response.message;
      
        file.previewElement.classList.add("dz-error");
        _ref = file.previewElement.querySelectorAll("[data-dz-errormessage]");
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            node = _ref[_i];
            _results.push(node.textContent = message);
        }

        return _results;
    },
     success: function(file,done) {
       alert(done);
    }
});
<div id="images" class="dropzone">
	</div>

The route:

Route::post('/ajax-uploadvehicleimage','VehicleAddController@uploadimg');

The controller:

public function uploadimg(){
         if (Request::hasFile('file'))
    {
        //houston we have a file!
        $file = Request::file('file');

        //move it to our public folder and rename it to $name
        Request::file('file')->move('images', 'insert_file_name.'.$file->getClientOriginalExtension());
        echo 'file uploaded!';
        var_dump($file);
    }else{
        echo 'no file, no bueno';
    }
    }

Can explain me whats the problem,and how can I change it or sample? I read a lot of topic about that but no one is releasd!

EDIT: Laravel.log:

[2017-01-13 07:55:38] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Can't use function return value in write context' in E:\bitnami\apache2\htdocs\vehicle\app\Http\Controllers\VehicleAddController.php:103
Stack trace:
#0 {main}  

Upvotes: 1

Views: 1407

Answers (1)

rchatburn
rchatburn

Reputation: 752

Try changing it to this

public function uploadimg(){
            $file = Request::file('file');
      if ($file) {
            //move it to our public folder and rename it to $name
            $file->move('images', 'insert_file_name.'.$file->getClientOriginalExtension());
            echo 'file uploaded!';
            var_dump($file);
        }else{
            echo 'no file, no bueno';
        }
     }

also when you go to the network tab on chrome when you upload it what is the response preview on the error?

Upvotes: 1

Related Questions