FILE UPLOAD ERRORS AND A FEW POSSIBLE SOLUTIONS TO CRUSH THEM (PHP.INI | NGINX.CONFIG)
There you are sitting at your computer – you have this great looking Drupal site underway and you have successfully created some content types with fields. One of the field-types is a “File” field and you are planning to use it to upload some fun new content to your site. You work your way through your newly created node-form filling in the necessary details, when you finally make your way to the “file upload” window. Happily ready to upload your first file, you select your file, click the upload button, and boom…You find yourself staring at the following error:
An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /file/ajax/field_publication_file/und/0/form-rA1IX_0P_4Q5BgFe11OLZ01zYi3zpAF777KHDKLKLxA
StatusText: n/a
ResponseText: 413 Request Entity Too Large
nginx/1.4.6 (Ubuntu)
ReadyState: undefined
Initially, the error seems to indicate that your file is too large – so your first instinct might be to find a way to increase your site’s ability to accept a larger file. You are on the right track. Out of the box, Drupal places a 2M limit on file-uploads. Try uploading anything larger and you are going to have a bad time. There are a number of ways to correct this issue; however, the most efficient and accepted way is to make some adjustments to your php.ini file.
Locate your php.ini file on the server; mine was located at (/etc/php5/cli). Once you have located your file, search for the following lines of code:
upload_max_filesize = 2M
post_max_size = 2M
and adjust them to reflect your newly increased limit:
upload_max_filesize = 50M
post_max_size = 50M
After you have made the necessary adjustments, save your new file and restart your server. Concluding the server-restart, clear your cache and now you should see the file upload increase reflected on your node-form. Yay!
Excited with your newly found Drupal prowess, you head for the “file-upload” window, select your file, click the upload button, and boom…You find yourself staring at the same error:
An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /file/ajax/field_publication_file/und/0/form-rA1IX_0P_4Q5BgFe11OLZ01zYi3zpAF777KHDKLKLxA
StatusText: n/a
ResponseText: 413 Request Entity Too Large
nginx/1.4.6 (Ubuntu)
ReadyState: undefined
What happened? As I stated earlier, an initial inspection of the error would indicate that your file is too large. But this cannot be the case since you just increased the file-limit via the php.ini file. While this step has not removed the error, it is highly recommended that you increase your php.ini file’s upload limit. Otherwise, you guessed it… You’re going to have a bad time with larger uploads.
What now? A closer look at the error-message (and some help from the DPE community, which is how I came across this solution) and you will see another clue about the error. Specifically, you’ll notice the line: nginx/1.4.6 (Ubuntu).
Solution? Locate your nginx.config file on the server; mine was located at (/etc/nginx). Once you have located your file, search for the section of code that starts with:
http {
#...
#...
}
and insert the following line of code between the brackets:
http {
#...
client_max_body_size 100m;
#...
}
After your file has been edited, saved, and uploaded to the server, restart your server using the following command line via Terminal or whatever Command Line Interface (CLI) that you prefer:
/etc/init.d/nginx restart
Concluding the server-restart, clear your cache and try uploading your file again.
Drum roll… NO ERROR!
My name is Charles Lavera and I am a new member of the Drupal community at Penn State. Specifically, I perform web-development for the Center of Advanced Language Proficiency Education and Research (CALPER) located within the College of the Liberal Arts. I hope you have found this information helpful. Open-source learning is a powerful tool that should be paid forward. In the spirit of this movement, I will be sharing future tips as I discover them so that we can continue moving forward in a productive manner as a community and as a team. Thanks for reading.
- Charles