Why can’t I upload big files and PHP memory_limit – Why do I get the error Allowed memory size of Xxx bytes exhausted?

Why can’t I upload big files (over a megabyte or two)?

The upload limits are enforced by the PHP / webserver configuration and not by Gallery 2. Craig Goranson wrote a very informative (but unfortunately Gallery 1 specific) email about how to fix this issue. Marcel Beemster updated it for Gallery2 at his blog.

In short: The administrator can change the upload_max_filesize and post_max_size directives in php.ini (the PHP configuration file). Also, you can try to override the system-wide default settings in a .htaccess file. Example, add this to your .htaccess file in your gallery2/ folder to set a upload limit of 10 Mega Byte:

 php_value post_max_size 10M
 php_value upload_max_filesize 10M

This can result in a “Internal Server Error” (error status 500) on all your Gallery pages. If you get an error after this change, remove your changes. That means that your webhost doesn’t allow such changes in .htaccess.

An alternative that works for some users: Add a php.ini file in your gallery2/ folder with the following contents (notice the difference, here we have a = and no php_value):

 post_max_size = 12M
 upload_max_filesize = 12M

This may or may not work. You can check if these changes have actually changed your limits by browsing to your add items -> from browser page.

Changing to bigger value “memory_limit =” might also help. Note though that the memory_limit does not have to be exceed the file size of the files that are uploaded. memory_limit plays a bigger role when using GD as your image toolkit module. More on that topic can be found in other FAQ entries.

If you’re using Apache 2, especially with something like RedHat, you may need to edit another directive, LimitRequestBody, as described in this forum post. Setting this directive to 0 (i.e. LimitRequestBody 0) will allow you to upload as big a file as you want (until you hit upload_max_filesize and/or post_max_size — see the above email link for more information).

Dreamhost customers (and perhaps customers of other providers) should try searching for specific instructions on how to accomplish this. In the case of Dreamhost, they provide a wiki page describing exactly how to accomplish it here. I have personally tested it and it works. It boils down to creating a cgi-bin directory, copying their cgi php handler and setting it to be your default php handler. They also provide information on how to create a script that keeps php.ini and php.cgi up to date, but with your settings instead of theirs.

Another option is to ftp to a folder on the local server and use the “Add Item” -> “From Local Server” option. You may need to rebuild the thumbnail for that item. This works on the 1and1 servers.

PHP memory_limit – Why do I get the error Allowed memory size of Xxx bytes exhausted?

You are exhausting the available memory that PHP has access to. In php.ini there is a config variable named memory_limit that by default is set to 8MB. Edit php.ini and increase it to a larger value (restart Apache afterwards). If you don’t have access to php.ini, you can add this line to your .htaccess file in your gallery2 folder. Usually, unless you are the owner of the server, you don’t have access to change php.ini. If there is no .htaccess file yet, you can create one (it’s just a text file with the name ‘.htaccess’).

php_value memory_limit [new memory limit]

To change it to 24 MB, write:

php_value memory_limit 24M

If the .htaccess method does not work or if you get an internal server error after adding this line, remove the line from the .htaccess again. You can also try to change the memory_limit by adding the following line right after ‘<?php ‘ in install/index.php and in main.php:


Trả lời

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Đăng xuất / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Đăng xuất / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Đăng xuất / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Đăng xuất / Thay đổi )

Connecting to %s

%d bloggers like this: