0

I've been facing this issue for many days i've searched the whole internet fixed my php.ini even the ngnix.confg file

Please tell me if anything is wrong with the code

i've edited the Cropper Plugin not to download but replace the current image. so what i did i used the ajax post to do it. PS: Ajax is sending huge data in post since it's a canvas and this whole process is working fine on localhost but not working on server. The whole site is on laravel but this code is on native php. I've also figured out that if image is small then it's working fine and if image is large then it's not working on server.

AJAX code in main.js file

$('.docs-buttons').on('click', '[data-method]', function () {
var $this = $(this);
var data = $this.data();
var $target;
var result;

if ($this.prop('disabled') || $this.hasClass('disabled')) {
  return;
}

if ($image.data('cropper') && data.method) {
  data = $.extend({}, data); // Clone a new one

  if (typeof data.target !== 'undefined') {
    $target = $(data.target);

    if (typeof data.option === 'undefined') {
      try {
        data.option = JSON.parse($target.val());
      } catch (e) {
        console.log(e.message);
      }
    }
  }

  if (data.method === 'rotate') {
    $image.cropper('clear');
  }

  result = $image.cropper(data.method, data.option, data.secondOption);

  if (data.method === 'rotate') {
    $image.cropper('crop');
  }

  switch (data.method) {
    case 'scaleX':
    case 'scaleY':
      $(this).data('option', -data.option);
      break;

    case 'getCroppedCanvas':
      if (result) {
        var temp =  $(' #image').attr('src');
        jQuery.ajax({
           url: '../../cropper/demo/save.php',
           type: 'POST',
           data: {
               data: result.toDataURL('image/jpeg'),
               name: temp,

           },
           complete: function(data, status)
           {
               console.log(data.responseText);
               if(status=='success')
               {             
                    $('#image').cropper("replace", temp);
               }
               else
                {
                    alert('Error has been occurred');
                }
           }
        });
      }
      break;
  }

  if ($.isPlainObject(result) && $target) {
    try {
      $target.val(JSON.stringify(result));
    } catch (e) {
      console.log(e.message);
    }
  }

}
});

save.php (To store the image on server)

<?php
$based64Image=substr($_POST['data'], strpos($_POST['data'], ',')+1);

$fileName='';
$fileName = substr($_POST['name'], 34);

$image = imagecreatefromstring(base64_decode($based64Image));


if($image != false)
{
    if(!imagejpeg($image,"..\..\images\image\\".$fileName))
    {
    //          fail;
    }
}
else
{
  //          fail;
}

?>

Please Help Thanks

Shahrukh Khan
  • 46
  • 1
  • 6

1 Answers1

0

Add the following to your conf file

fastcgi_buffers 16 16k; 
fastcgi_buffer_size 32k;

For more details and understanding please read https://gist.github.com/magnetikonline/11312172#determine-fastcgi-response-sizes

These results may not be accurate, so reading to ensure your proper configuration is advised

Bruce
  • 1,039
  • 1
  • 9
  • 31
  • http://testing2.vire-news.com/public/consumer/create Please check this is the link – Shahrukh Khan Sep 30 '16 at 10:51
  • Checked the link, got an error message about localhost not being allowed to connect to the mySQL server that contained your login and password. –  Sep 30 '16 at 11:12