Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
2.4k views
in Q2A Core by
edited by
If I upload an image file (eg: 3MB) for avatar. It will take some time to process and refresh the page. Then nothing happens and the avatar stays the same. There should be some error message like File Exceeds Max Size at least let user know what to do next.

And also if I'm trying to upload a BMP file where is no error message too.

I tried under this site too. The above problems exist here.

Anyone come acress the same problem and any idea?

Thanks !
Q2A version: 1.6.3
by
Do you correctly see (bottom left of the browser) the "Uploading" percentage value increasing when you are saving the avatar ?
http://www.question2answer.org/qa/?qa=blob&qa_blobid=10683977642598209040
Does it reach the 100% value ?
Test it on the demo site.
by
yes, after 100%, the page refreshed and nothing happened, the image was not set.
by
I cannot  reproduce your issue. Could you share an avatar image that has the issue ?
by
@pupi1985 has solved this problem. You can see the best answer below !

1 Answer

+3 votes
by
edited by
 
Best answer

Most likely you should blame a PHP configuration.

As you said "nothing happens" I bet the post_max_size or maybe upload_max_filesize are to blame. Take these values from the phpinfo() output or php.ini file. Compare those limits with the size of the image you're trying to upload and make the appropriate changes.

Note the size of an HTTP post is not the same as the size of the attached file while the upload size should match the size of the attached file.


Additional detail: Without overcomplicating things too much I can think of the following scenarios, assuming upload_max_filesize and post_max_size are configured in a way that makes sense (EG: upload_max_filesize should be smaller than post_max_size... even if they were equal it wouldn't make sense):

  • Uploaded file size <= upload_max_filesize (arguably assuming the HTTP request size <= post_max_size)
    • $_FILE array is set and contains
      • size: The size of the file
      • error: 0
    • $_POST array is set and contains all the needed variables
  • Uploaded file size > upload_max_filesize (arguably assuming the HTTP request size <= post_max_size)
    • $_FILE array is set and contains
      • size: 0
      • error: 1
    • $_POST array is set and contains all the needed variables
  • HTTP request size > post_max_size (arguably assuming the uploaded file size, if any > upload_max_filesize)
    • $_FILE array is not set
    • $_POST array is not set

I guess any other scenario doesn't make much sense to consider or to take any particular action.

I've created this pull request https://github.com/q2a/question2answer/pull/57 with all the changes performed in the code to handle this situation in the account page and in the admin page (uploading a default avatar). You can give them a try by backing up those for files and then replacing them with the ones of the pull request. Then track the pull request for feedback on it and, of course, let me know if you have any issue with it.

 

by
Yes I found it be to 2M in my computer. So is there a way to capture this error and display it to users? Thank you !
by
The problem is this is not an exception that can be caught in PHP nor there is a post_max_size_error flag to check. However, you can try to infer you're facing this situation by inspecting some variables as explained in http://stackoverflow.com/a/2133726/268273 . I also agree with the "poor design decision".
by
Thank you ! I'm trying to display some explanation for user to limit the size of file !
by
I've updated the answer to handle the different scenarios that these variables generate.
...