uSked / mosaico-php-backend

A PHP backend for Mosaico
GNU General Public License v3.0
32 stars 34 forks source link

Upload not working #2

Closed kbalajijan1 closed 8 years ago

kbalajijan1 commented 8 years ago

Hi,

Following else if condition of upload/index.php is not satisfied. Could you help me on this.

else if ( !empty( $_FILES ) ) { //image upload codes }

Also, may I know what has been used to upload the images without form submit(page load).

Thanks

kbalajijan1 commented 8 years ago

Hi

I am getting struck here. Can you give me some clue on this

Thanks

mherbold commented 8 years ago

The $_FILES is supposed to be populated by PHP whenever a file has been uploaded. If $_FILES is empty then PHP thinks no file has been uploaded. I believe that the file is uploaded via an ajax request simulating a submit form by Mosaico. I would check the apache logs on the server to see if something is happening such as a HTTP redirect causing the POST data to be lost.

kbalajijan1 commented 8 years ago

Hi

Thank you for your response. Please find below the screenshot of console after uploading.

url_log

Is uploading working fine to you? Have you modified anything apart from Github code for upload.

Could you suggest something to make it work.

Thanks

mherbold commented 8 years ago

You are getting a 301 redirect as I have suspected. For my installation I did modify the editor.html file to add a trailing slash "/" to the fileuploadConfig url to prevent the redirect. I did the same thing for emailProcessorBackend.

  var ok = Mosaico.init({
    imgProcessorBackend: 'img',
    emailProcessorBackend: 'dl/',
    titleToken: "MOSAICO Responsive Email Designer",
    fileuploadConfig: {
      url: 'upload/',
      // messages??
    }
  });
kbalajijan1 commented 8 years ago

Hi,

Thank you. It's my mistake. I don't know how the trailing slash had been removed from editor.html. Now adding trailing slash allows me to upload.

Now I can see my uploaded image in the uploads directory but the image NOT shown in the image block in editor.html after uploading. Any idea?

Still I can see image src as img/?method=placeholder&params=534%2C200.

I am getting following error message Errore inaspettato durante il caricamento(SyntaxError: Unexpected token <) after uploading.

Thanks

mherbold commented 8 years ago

The placeholder image is generated by ImageMagick - if it does not work then most likely you don't have ImageMagick installed or don't have the PHP module for ImageMagick working.

kbalajijan1 commented 8 years ago

Hi,

I have installed ImageMagick already. Placeholder images are created and displayed properly after using your php backend code.

My issue is after uploading still I see only placeholder image(534x200) instead of the uploaded image.

Thanks

mherbold commented 8 years ago

Did you drag and drop the image you have uploaded into the placeholder image? If you can see the images you have uploaded in your image library then it should be all working.

kbalajijan1 commented 8 years ago

Hi,

As you said, I have created $thumbnails_dir and $static_dir and given write permission. Now I can see the image files in the $thumbnails_dir but images are blank and black.

i.e. In $uploads_dir directory I can see the proper image but after Imagick's resizeImage the images get recreated in $thumbnails_dir but the images are blank and black color, unable to see the actual image in $thumbnails_dir.

Could you give me a clue on this. If this upload works fine then everything will be fine.

Thanks

mherbold commented 8 years ago

ImageMagick must be generating black images for some reason. I do not know why. Perhaps ImageMagick is failing to load the source (original) image. To narrow down the issue try uploading an image with a simple file name like "test.jpg" - just to eliminate the possibility that the issue might be due to a file name error due to urlencoding/urldecoding.

kbalajijan1 commented 8 years ago

Hi,

I changed the image name to test.jpg but no luck.

I also tried to hard-code the image path in Imagick class object and change the filter to Imagick::FILTER_BOX but still it generates black image.

I use the following: Imagick module version: 3.1.2 ImageMagick version: 6.7.7-10

I installed imagick using the following command: sudo apt-get install php5-imagick

May I know what version do you use?

Thanks

kbalajijan1 commented 8 years ago

Hi,

Can you able to resize the image properly. Because after I searched in web I come to know that the problem is the blur value. 0 will result in a black image. The blur factor where > 1 is blurry, < 1 is sharp.

Change the 0 into 0.9 in upload/index.php works fine.

$image->resizeImage( $thumbnail_width, $thumbnail_height, Imagick::FILTER_LANCZOS, 0.9, TRUE );

I have done the same thing in img/resize.php

Thanks

mherbold commented 8 years ago

Hello - If you get latest code from here you will see that I already changed the blur value to 1.0.

However, even when it is at 0.0 it should not result in a black image - 0.0 works for me, the picture was just very sharp (basically blur of 0.0 is point filtering).

kbalajijan1 commented 8 years ago

OK. I will use your latest commit. Thank you for your help. Amazing work.