Note: You are currently viewing documentation for Moodle 2.9. Up-to-date documentation for the latest stable version of Moodle may be available here: Jon Witts/file-upload-v2.

User:Jon Witts/file-upload-v2: Difference between revisions

From MoodleDocs
No edit summary
 
(31 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Probably the most frequently asked question in the Moodle.org Using Moodle forums is "How do I increase the upload file size limit?"  
Probably the most frequently asked question in the Moodle.org Using Moodle forums is "How do I increase the upload file size limit?" Uploading files in Moodle is controlled both externally, within the server environment, and internally by Moodle - this is the nature of the Internet and cannot be avoided.  While this page will primarily focus upon making changes in on the server environment, outside of the Moodle interface, it will also look at the changes you can make inside Moodle. 


File Upload sizes are restricted in a number of different places. The list below shows the order of inheritance that file upload sizes follow.
There are different web server operating systems, thus the method of increasing the uploaded file limit can be different in each.  Typically this process is controlled directly by PHP, but some web server systems can override php settings.


#PHP Server level - [[File_upload_size]]
==Overview==
#Moodle site level - [[Site_policies]]
#Course level - [[Course_settings]]
#Activity level - [[Adding/editing_a_forum]], [[Upload_a_single_file_assignment]] and [[Advanced_uploading_of_files_assignment]]


As you can see from the list above, it is the PHP server level that has the greatest precedence. So to increase the file upload size in Moodle we must first adjust this setting. Before we try to adjust any settings in PHP though it is good to know what is set already. We find this out by using a phpinfo script.
File Upload sizes can be restricted in a number of different places. The list below shows the order of inheritance that file upload sizes follow.


==PHP Info Script==
#PHP Server level - [[File_upload_size|File upload size]] (which is this page)
Create a phpinfo() page or locate the phpinfo section in your Moodle, as per the instructions here: [[phpinfo]]
#Moodle site level - [[Site_policies|Site Policies]]
#Course level - [[Course_settings|Course Settings]]
#Activity level - [[Adding/editing_a_forum|Adding/Editing a Forum]], [[Upload_a_single_file_assignment|Upload a Single File Assignment]] and [[Advanced_uploading_of_files_assignment|Advanced Uploading of Files Assignment]]


At the very top of the phpinfo page you will see the version of PHP that your server is running. See the relevant section below for information on how to proceed.
As you can see, it is the PHP server level that has the greatest precedence. So to increase the file upload size in Moodle we must first adjust this setting. You will need to find out where the active php.ini is located and if another program is over riding it.
===PHP Version is 5===
If you are using PHP 5, there may be many php.ini files on your server, but only one will be the active one. Modifying any copy other than the active one will do absolutely no good whatsoever. To find the active one, do the [[phpinfo]] thing. In the output, near the top of the page, is an item labeled Configuration File (php.ini) Path. This will tell you exactly where the active file is. This is the php.ini that your PHP install is reading.


===PHP Version is 4===
==Php.ini changes==
If you are using PHP 4 you will need a php.ini file in every folder (directory) with php script files.
Here are the changes you might make to a php.ini file.  For those who need more information, please continue reading other sections in this page.
 
After find the correct php.ini file, look for and change two variables.  In the example below, we found the following lines set the max file size to 512 megabytes. 
 
upload_max_filesize = 512M
post_max_size = 512M
 
This may seem large, but do not forget, the Administrator can go to '''Front Page ► Administration ► Courses ► Course default settings''' and reset the maximum file upload size to whatever level required. It also means that if someone needs a maximum file size temporarily, say a multimedia teacher uploading a large file, the Administrator can reset these values in the same location, and set them back again later.
 
==Find php.ini control information==
For those who are continuing on and need more information, you may need to find the php.ini file that controls the size of the upload files.
 
*In PHP 4.x there must be a php.ini file in every directory that has php scripts.
*In PHP 5.x there is only one php.ini file that is active.  There maybe many php.ini files on the server, but only one will effect the file upload size.  You can find this file by writing a php script or using the Moodle interface.
*Some Application Programming Interface (API) servers will handle php settings differently
 
===Moodle php info===
The easiest way to find the location of the controlling php.ini files in Moodle 1.7 onward is to call up Site administration block>Server>PHP info. This will run an information script.
 
*Server API - shows the server type
*Configuration File (php.ini) Path - show the location of the file.
*Loaded Configuration File (if there)- will over ride the above location.
 
 
===Phpinfo script===
For Moodles prior to 1.7 or on  any server, you can create your own information page. Follow the instruction at [[phpinfo]] for more information.
 
At the very top of the phpinfo page you will see the version of PHP that your server is running.  
 
* Loaded Modules: For example Apache2Handler
*


==What web server are you using?==
==What web server are you using?==
===Apache===
===Apache===
If you are using an Apache web server you can use .htaccess files to over ride the php.ini settings, or you can edit the active php.ini files on your server.
If you are using an Apache web server you can use .htaccess files to override the php.ini settings, or you can edit the active php.ini files on your server. Look for the API as Apache Handler.  After making changes, you will have to restart your server.
 
Add the below to your .htaccess file
    * php_value upload_max_filesize 512M
    * php_value post_max_size 512M
 
===IIS===
===IIS===
.... edit php.ini ?! ...
There seems to be a double whammy for IIS. Not only is there a restriction in file size uploads for PHP there is also one for IIS. To change the PHP limit is the same as is described above, at the start, change those two variables already mentioned. The next issue is with IIS. This comes from [http://msdn.microsoft.com/en-us/library/ms524953.aspx Microsoft's knowledge base.] Unfortunately, like most Microsoft documentation, it is not all that clear.
 
  MaxRequestEntityAllowed
  The MaxRequestEntityAllowed property specifies the maximum number of bytes allowed in the entity body of a request.
  If a Content-Length header is present and  specifies an amount of data greater than the value of
  MaxRequestEntityAllowed, IIS sends a 403 error response.
 
  The metabase represents unlimited as the DWORD value of 4294967295 (0xFFFFFFFF); however, VBScript represents unlimited in hexadecimal format as &HFFFFFFFF.
  Previous versions of IIS represented unlimited as -1.
 
There is a lot more, but this should provide you with the basic knowledge you need to be able to change the upload file size limits. 
 
 
====FastCGI====
To make PHP work a little better in IIS, you can utilize the FastCGI component, information about which can be found in this [http://www.iis.net/ConfigReference/system.webServer/fastCgi php.iis.net] site.
 
===Other===
===Other===
??
??


==How is php running on your web server?==
==How is php running on your web server?==
The manner in which PHP is running on your web server will determine if you need to restart your web server daemon or not to apply changes you make to the php.ini file.
PHP can interact with other programs on your web server.  If PHP is being controlled by an Apache Handler, you will have to restart your server.  The changes will take place immediately if you are running API server using say CGI/FastCGI .


You can find out how your web server is running PHP by looking at this section of your phpinfo page: Apache2Handler > Loaded Modules Section.
You can find out how your web server is running PHP by looking at:
*Site administration>Server>PHP info "Server API" 
*phpinfo page: Apache2Handler > Loaded Modules Section.


===mod_php5 is present===
You are running PHP as an Apache Module. You will need to restart Apache to make changes to your php.ini file apply.


===??===
===??===
==What access do you have to the server?==
==What access do you have to the server?==
To make changes to the main php.ini file you will need administrative access to the server...
To make changes to the main php.ini file you will need administrative access to the server...
Line 42: Line 90:
...
...
===Shared / Hosted access to server===
===Shared / Hosted access to server===
...
==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.
 
:It might be a good idea to talk to with your service provider before you attempt anything.  They probably have instructions on "how to" and may have their own limits for uploaded file size. Some hosts measure the file size in gigabytes and others in megabytes.  If you are unhappy with their limits, then check your contract and consider changing your provider to one that has a limit and price that you like.   
 
===.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 should already have a standard file in place or you can copy it from another location. 
 
To the .htaccess file find or 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 moodle root .htaccess file and will tell you to use a php.ini file for php directives.  The steps are basically the same as we covered above and your host will probably be running PHP 5.x
*Locate the key php file.  It probably will not be located with your Moodle code.
*Using a file edit program, change the upload max and post max size in the active php file.
 
For example we found the following lines and the max file size is 20 megabytes. 
 
upload_max_filesize = 20M
post_max_size = 20M
 
 
==See also==
*[[Installing Moodle/Creating custom php.ini files]]
*[[Beginning Administration FAQ]]

Latest revision as of 08:29, 18 April 2010

Probably the most frequently asked question in the Moodle.org Using Moodle forums is "How do I increase the upload file size limit?" Uploading files in Moodle is controlled both externally, within the server environment, and internally by Moodle - this is the nature of the Internet and cannot be avoided. While this page will primarily focus upon making changes in on the server environment, outside of the Moodle interface, it will also look at the changes you can make inside Moodle.

There are different web server operating systems, thus the method of increasing the uploaded file limit can be different in each. Typically this process is controlled directly by PHP, but some web server systems can override php settings.

Overview

File Upload sizes can be restricted in a number of different places. The list below shows the order of inheritance that file upload sizes follow.

  1. PHP Server level - File upload size (which is this page)
  2. Moodle site level - Site Policies
  3. Course level - Course Settings
  4. Activity level - Adding/Editing a Forum, Upload a Single File Assignment and Advanced Uploading of Files Assignment

As you can see, it is the PHP server level that has the greatest precedence. So to increase the file upload size in Moodle we must first adjust this setting. You will need to find out where the active php.ini is located and if another program is over riding it.

Php.ini changes

Here are the changes you might make to a php.ini file. For those who need more information, please continue reading other sections in this page.

After find the correct php.ini file, look for and change two variables. In the example below, we found the following lines set the max file size to 512 megabytes.

upload_max_filesize = 512M
post_max_size = 512M

This may seem large, but do not forget, the Administrator can go to Front Page ► Administration ► Courses ► Course default settings and reset the maximum file upload size to whatever level required. It also means that if someone needs a maximum file size temporarily, say a multimedia teacher uploading a large file, the Administrator can reset these values in the same location, and set them back again later.

Find php.ini control information

For those who are continuing on and need more information, you may need to find the php.ini file that controls the size of the upload files.

  • In PHP 4.x there must be a php.ini file in every directory that has php scripts.
  • In PHP 5.x there is only one php.ini file that is active. There maybe many php.ini files on the server, but only one will effect the file upload size. You can find this file by writing a php script or using the Moodle interface.
  • Some Application Programming Interface (API) servers will handle php settings differently

Moodle php info

The easiest way to find the location of the controlling php.ini files in Moodle 1.7 onward is to call up Site administration block>Server>PHP info. This will run an information script.

  • Server API - shows the server type
  • Configuration File (php.ini) Path - show the location of the file.
  • Loaded Configuration File (if there)- will over ride the above location.


Phpinfo script

For Moodles prior to 1.7 or on any server, you can create your own information page. Follow the instruction at phpinfo for more information.

At the very top of the phpinfo page you will see the version of PHP that your server is running.

  • Loaded Modules: For example Apache2Handler

What web server are you using?

Apache

If you are using an Apache web server you can use .htaccess files to override the php.ini settings, or you can edit the active php.ini files on your server. Look for the API as Apache Handler. After making changes, you will have to restart your server.

Add the below to your .htaccess file

   * php_value upload_max_filesize 512M
   * php_value post_max_size 512M

IIS

There seems to be a double whammy for IIS. Not only is there a restriction in file size uploads for PHP there is also one for IIS. To change the PHP limit is the same as is described above, at the start, change those two variables already mentioned. The next issue is with IIS. This comes from Microsoft's knowledge base. Unfortunately, like most Microsoft documentation, it is not all that clear.

 MaxRequestEntityAllowed
 The MaxRequestEntityAllowed property specifies the maximum number of bytes allowed in the entity body of a request. 
 If a Content-Length header is present and  specifies an amount of data greater than the value of 
 MaxRequestEntityAllowed, IIS sends a 403 error response.
 
 The metabase represents unlimited as the DWORD value of 4294967295 (0xFFFFFFFF); however, VBScript represents unlimited in hexadecimal format as &HFFFFFFFF. 
 Previous versions of IIS represented unlimited as -1.

There is a lot more, but this should provide you with the basic knowledge you need to be able to change the upload file size limits.


FastCGI

To make PHP work a little better in IIS, you can utilize the FastCGI component, information about which can be found in this php.iis.net site.

Other

??

How is php running on your web server?

PHP can interact with other programs on your web server. If PHP is being controlled by an Apache Handler, you will have to restart your server. The changes will take place immediately if you are running API server using say CGI/FastCGI .

You can find out how your web server is running PHP by looking at:

  • Site administration>Server>PHP info "Server API"
  • phpinfo page: Apache2Handler > Loaded Modules Section.


??

What access do you have to the server?

To make changes to the main php.ini file you will need administrative access to the server...

Local / Full access to server

...

Shared / Hosted access to server

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.

It might be a good idea to talk to with your service provider before you attempt anything. They probably have instructions on "how to" and may have their own limits for uploaded file size. Some hosts measure the file size in gigabytes and others in megabytes. If you are unhappy with their limits, then check your contract and consider changing your provider to one that has a limit and price that you like.

.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 should already have a standard file in place or you can copy it from another location.

To the .htaccess file find or 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 moodle root .htaccess file and will tell you to use a php.ini file for php directives. The steps are basically the same as we covered above and your host will probably be running PHP 5.x

  • Locate the key php file. It probably will not be located with your Moodle code.
  • Using a file edit program, change the upload max and post max size in the active php file.

For example we found the following lines and the max file size is 20 megabytes.

upload_max_filesize = 20M
post_max_size = 20M


See also