hits counter
  Create Free Blog | Random Blog »   Report Abuse | Login   

 
13th Dec, 2008

Change the Maximum Upload size with PHP


Depending on how you host your website (or application) there are different ways to change the PHP settings. In particular, the most asked about problem, changing the maximum upload size.

There are 3 settings PHP uses that limit your uploading ability:

  • post_max_size
    This is the combined maximum size of all files sent on the form. If you have 2 file fields on your form, the total filzesize of the 2 files must not exceed the post_max_size value.
  • upload_max_filesize
    This is the filesize limit of each individual file.
  • memory_limit
    PHP scripts have a memory limit, and generally speaking this can prevent some uploads from working. The limit should be set at a reasonable level, of course you won’t need 20mb for a simple ‘hello world’ script. Try slowly increasing this value if you find that uploads still aren’t working.

If you host your site remotely, you should check their documentation on how to change the PHP configuration settings. But if you’re not so inclined, and prefer a trial and error approach, here’s a summary of things to try:

Change php.ini directly

If you host your site on a server that you have access to, you can change your php.ini file directly. This is the easiest approach. Your php.ini file should exist in the PHP installation directory. Open it in your favourite text editor and search for these lines and change them:

memory_limit = 8M
post_max_size = 8M
upload_max_filesize = 2M

You may need to restart apache for the changes to take effect.

Changes to .htaccess

.htaccess files only apply to Apache webservers. They are files that append and change certain values that apache uses and they are placed in the root folder (and all folders beneath will use those settings). If apache uses PHP as a Module, then you can add values to the .htaccess file:

php_flag file_uploads On
php_value memory_limit 8M
php_value post_max_size 8M
php_value upload_max_filesize 2M

If you try this approach, and your webserver displays a 500 interal server error, then PHP is not runing as a module and apache didn’t like the php_value entries. You will need to remove your changes.

Upload a php.ini file

This generally works if the changes to .htaccess method doesn’t. Some web hosts that use apache, also use PHP as a CGI. Then also, most times, this allows changes to the PHP configuration using a custom php.ini file that you can upload. You don’t want to include every setting available to PHP in your file. Only include the ones you want to change, and don’t forget the heading [PHP]:

[PHP]
; Whether to allow HTTP file uploads.
file_uploads = On
; Maximum amount of memory a script may consume (8MB)
memory_limit = 8M
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M 
Share SocialTwist Tell-a-Friend 
Generated Keywords for the page : php file upload , php upload limit , file upload , php upload , php ini , upload , php , , php upload large files , php uploading files , upload folders , ajax file uploader , asp net large file upload , fast upload , file upload code , file upload script , free upload , large file upload , php large upload , upload form , upload gif , upload large files , upload script , ajax file upload , ajax upload , asp net ajax file upload , asp net multiple file upload , asp upload , file upload applet , file uploading asp net , file uploads , html upload , php file upload settings , php file upload size , php upload big file , php upload big files , php upload file size limit , php upload images , php upload large file , php upload limit size , php upload limits , php upload photo , php upload picture , php upload settings , php upload size , php uploading images , php uploading large files , upload applet , upload files , upload manager , upload music , upload video , upload videos , uploading video , web file upload , ajax file upload php , apache php file upload , apache php upload , apache php upload limit ,

Responses

Hi antervedi I have read your full article and i am completely satisfy from u. There are few person who can express themself and i like your article. But if u write on thinkarticle.com you will get better response as the system is more powerful there. So like to see you on thinkarticle.com.

Leave a response

Your response:

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image

Categories