-6

I am trying to upload image on server using ajax post.

I am facing problem with big size images. For example i can upload 1MB image without problem, but when i try to upload 5MB image file $_FILES['errors'] return Please select file message.

The ajax call i currently use.

    var request = $.ajax({
        url: '/uploadguides',
        dataType: 'json',
        cache: false,
        contentType: false,
        processData: false,
        data: formData,
        type: 'post',
        async: false
    });

In php.ini i have set post_max_size = 3M, upload_max_filesize = 64M.

I thought it was post_max_size limit problem i have increased it to 20M but same result

Mikheil Janiashvili
  • 497
  • 1
  • 6
  • 18

1 Answers1

0

First - I found this by Googling getting images:

https://github.com/blueimp/JavaScript-Load-Image

Second, why use AJAX? Doesn't the built-in Javascript Image set up automatically load in an image when you change the source? Like so:

var img = new Image();
img.src = "Path to image";

If you use the above - all you do is to check the width of the image in order to know it has been loaded. Just make a little function to check if the file has been loaded like so:

function checkImage()
{
     if( img.width < 1 ){
        setTimeout( "checkImage()", 100 );
        return;
        }

     tellMeItIsLoaded();
}

Or take a look at this article

Load Image from javascript

Community
  • 1
  • 1
Mark Manning
  • 1,427
  • 12
  • 14
  • well its good topic but not solution for my problem, i know if the file is uploaded in browser, i have checking like that but $_POST and $_FILES are empty in my case. – Mikheil Janiashvili Jan 07 '16 at 14:11
  • You need to post a link to the image so people can try uploading it. Maybe there is a problem with the file rather than the javascript. After all, everything I posted can handle ANY size file. So - first - if you aren't even going to try our solutions then there isn't any reason to try to help you and secondly - if you DO try our solutions and they do not work - then it is not because of what we posted but because something else isn't working and that only leaves the file itself. Remember - not everything in the entire world has to go through AJAX. – Mark Manning Jan 07 '16 at 14:21
  • im glad for your solution but the problem i was facing was wamp servers problem unfortunatelly, i have upgraded it to latest version configured php and it worked, something was wrong with server and not with code actually, i haven't tested your solution as i was sure that i had file in browser was just to move it, and if it worked for lower size files than it must work for higher sizes but appeared that post_max_size wasn't upgraded on server... – Mikheil Janiashvili Jan 07 '16 at 14:33
  • Glad you got it to work. If all of this work is being done on your personal computer - that should have been mentioned. Last, but not least - you should load your image into Photoshop and set the dpi down to 96dpi. That is the standard dpi now for LCD and LED screens. So using a 300dpi image on a 96dpi screen does not give you a better image. It just makes the image larger. Also, if you are using fewer than 37000 colors you might want to look at GIF file format. The GIF file format can do 256*256 colors per line in the 89a file format. It could make that 5MB image become a 256KB image. – Mark Manning Jan 07 '16 at 22:12