File upload size

From MoodleDocs
Revision as of 11:55, 8 March 2010 by chris collman (talk | contribs) (→‎Hosted Server: reorganiize for hosted server, more edits to come)

Probably the most frequently asked question in the Moodle.org Using Moodle forums is "How do I increase the upload file size limit?" The changes that need be made are the same in all versions of Moodle, just in different OS' they need be made in different places. Upload file sizes are restricted in a number of ways and each one in this list restricts the following ones:

Server level
Moodle site level
Course level
Activity level

This is a contentious issue, mainly because you might think that it should be set inside the Moodle. Unfortunately, this is not so, these are environment issues that need to be set in the server and PHP folders, Moodle cannot work outside itself.

Physical access to Server

These instructions assume you have full physical and administrative access to your server. If you are using a hosted server then you will probably need to look into other ways to increase your file upload size.

There are positives and negatives to both methods below. If you modify the pnp.ini file then the changes will effect all php applications on your server. Since PHP5 you can only have one php.ini file on your server. The php.ini method will work with all web servers though. The .htaccess method will only effect the folder and all subfolders that it is placed in, but you must have certain settings enabled in Apache.

Modifying the php.ini file

These instructions show you how to change the file upload size by editing your php.ini file.

Ubuntu Linux Instructions

These instructions assume that you have installed the standard Moodle package, PHP 5 and Apache 2 via apt-get and left it all as a default install. If you have compiled yourself I presume that you will know where your php.ini files are!

You need to edit the following three settings in your php.ini file located at: /etc/php5/apache2/

  • Type "sudo nano /etc/php5/apache2/php.ini"
  • Press Ctrl and W and type "post_max_size"
  • Change the value to the number of Mb you want your site to accept as uploads
  • Press Ctrl and W and type "upload_max_filesize"
  • Change the value to the number of Mb you want your site to accept as uploads
  • Press Ctrl and W and type "max_execution_time"
  • Change the value to 600
  • Press Ctrl and O
  • Press Ctrl and X
  • Type sudo /etc/init.d/apache2 restart

Your new file size limit should now appear in Administration > Security > Site Policies > Maximum uploaded file size

Windows XP and Server 2003 Instructions

These instructions presume that you have downloaded the latest PHP 5.2.x Windows zip package and extracted it to C:\PHP. If you have installed PHP to another location then change all references to "C:\PHP" to the location you installed PHP too.

  • Open C:\PHP
  • Right Click the php.ini file in this folder and choose "Open with..."
  • Choose "Wordpad" not "Notepad" to open the file with (Notepad does not properly use the UTF-8 Character set and it's carriage returns can cause problems)
    • Better still download and install any text editor that can save the file in a UTF-8 format, Crimson Editor is one such, and use that instead of either Wordpad or Notepad!
  • Press Ctrl and F and type "post_max_size"
  • Change the value to the number of Mb you want your site to accept as uploads
  • Press Ctrl and F and type "upload_max_filesize"
  • Change the value to the number of Mb you want your site to accept as uploads
  • Press Ctrl and F and type "max_execution_time"
  • Change the value to 600
  • Press Ctrl and S
  • Exit Wordpad
  • Restart your webserver
    • For IIS
    • Open your Start Menu on your server and select "Run"
    • Type "iisreset /RESTART"
    • For Apache 2
    • The following command will work as long as you have installed Apache 2 as a service on your Windows Server
    • Open your Start Menu on your server and select "Run"
    • Type "httpd -k restart"

Your new file size limit should now appear in Administration > Security > Site Policies > Maximum uploaded file size

NOTE: These instructions should also cover the Xampp Windows installer. Just replace C:\PHP with C:\Moodle\server\php and to restart your Moode with a normal stop-start.

Modifying the apache config file

Ubuntu Linux Instructions

You may also need to edit the config.php file in the moodle directory:

  • Type "gksudo nautilus" to get root permissions
  • Navigate to /etc/moodle
  • Open apache.conf
  • Go to the "<IfModule mod_php5.c>" section
  • Change "php_value upload_max_filesize = 2M" to a higher value
  • Change "php_value post_max_size = 2M" to a higher value
  • Go to the "<IfModule mod_php4.c>" section
  • Change "php_value upload_max_filesize = 2M" to a higher value
  • Change "php_value post_max_size = 2M" to a higher value
  • Save file
  • Type sudo /etc/init.d/apache2 restart


Modifying the .htaccess file

The following instructions will only work on an Apache web server, and also the Apache server must have Overrides allowed.

Create a file called .htaccess in Moodle's main directory (where 'index.php' is located, not the 'moodledata' directory) that contains the following information:

php_value upload_max_filesize 20971520
php_value post_max_size 20971520
php_value max_execution_time 600

20971520 is the integer value for 20Mb. You can use the following site to convert MegaBytes to Bytes.

Hosted Server

Things can be a little different with a hosted server for uploaded and downloaded file size. You are probably going to to be told to create or change a .htaccess file, or to modify a php.ini file.

You may need to discuss the matter of uploaded file size with your service provider. Their rules of use may place limits on uploaded and downloaded file sizes and they may be unwilling to allow too much latitude here. Always remember though, they are providing the service, but you are the customer - so if you do not like their rules, look for another provider. Taking your business elsewhere can be a powerful incentive to changing people's attitudes. Make sure you can move before you inform them that you are unhappy with their rules though - you may be tied by contract or other reasons.

.htaccess with hosted server

The one purpose of an .htaccess file is to override the the current limitations of both the server and the php.ini file. Your hosted server should inform you where that file needs be placed in your Moodle, but generally in the root is sufficient. They may already have a standard file you can use, if so, use it - but perhaps not.

To the .htaccess file add the lines:

 php_value upload_max_filesize 128M
 php_value post_max_size 128M
 

This will limit uploads to 128MB, but you can make it any size you agree with your provider. The wording may vary slightly, according to the demands of the server.

php.ini with hosted server

Some servers will not allow you to change the root .htaccess file and tell you to use a php.ini file for php directives. Here you can use the instruction located in the above sections.

See Also