2

I use cropper.js to crop an image. Cropping and displaying works well.

I now want to upload the image using jQuery's Ajax to the directory /uploads (the permissions are set correctly)

Problem: The image is not uploaded, actually nothing happens.

croppedCanvas = $image.cropper('getCroppedCanvas', {
width: 320,
height: 320, 
  });

croppedCanvas.toBlob(function (blob) {
    var form_data = new FormData();
    form_data.append('croppedCanvas', blob);

    $.ajax('upload.php', {
        type: "POST",
        data : form_data,
        contentType: false,
        cache: false,
        processData:false,
        mimeType:"multipart/form-data"
    }).done(function(res) {
        console.log('Upload success');
    });
});'

Instead of

$.ajax('upload.php', {
    type: "POST",

I also tried to upload directly (like recommended on https://github.com/fengyuanchen/cropper

$.ajax('/uploads', {
    type: "POST",

but neither the image is uploaded nor my php-script "upload.php" is executed.

However, the console says "Upload success"

FlyingFlo
  • 19
  • 5
  • What do you have in upload.php? – Rotimi Oct 02 '17 at 17:12
  • upload.php definitely works. I have the problem that it is not even executed. Furthermore, I think it should also work without upload.php through direct upload to the directory like explained in the link (section getCroppedCanvas([options])) – FlyingFlo Oct 03 '17 at 08:44

0 Answers0