It is possible to configure upload_max_filesize via . htaccess

Asked

Viewed 1,345 times

2

Is it possible to configure the php upload_max_filesize by the . htaccess file? Since I don’t have access to the php.ini server file.

  • +1 great question. I was going to answer that there was no way, but a brief researched (in English) I discovered that there is a way.

  • @Skramewell We are a community not only to answer things that have no answer, but to bring content, this kind of comment sounds bad, another thing not everyone is familiar with English, the idea of the community is also to bring good content in Portuguese from here to the other side of the Atlantic. Please understand as a constructive criticism and welcome to the community.

3 answers

2


To complement the other answer, to use php setup by . htaccess you must have installed the mod_php, if your server or hosting has no availability will appear an error message on all error pages 500 Internal Error Server, similar to this:

500 internal server error

If your hosting/server allows installing things per terminal (ssh) you can try something like (being Debian or Ubuntu):

sudo apt-get install libapache2-mod-php5

Note that you will need to restart the server, however if you do not have access to SSH then you will need to contact support to enable.

See the mod_php settings differences:

  • php_flag is used when there are boolean values, which php.ini settings accept only 1 or 0, On or Off and true or false, for example:

    php_flag display_startup_errors off
    php_flag display_errors off
    
  • php_value is used when it’s not about turning on or off (like On and Off), in case we use to set paths and limits in megas, for example:

    php_value  upload_max_filesize  25M
    php_value error_log  /foo/bar/baz/erros.log
    
  • php_admin_flag cannot be used on . htaccess, you can only configure it in Apache and this allows you to override which php.ini configuration, unlike the previous ones that have limitations.

It is also interesting to note that many servers do not allow editing php.ini and has not mod_php but they have the option to edit a file on the local user that overwrites some flags or values of php.ini (see support for availability), an example is PHPRC (PHP Runtime Configuration or PHP runtime configuration), you will have to check if there is this availability.

The interesting thing about PHPRC, is that it is often possible to create a configuration file for each version of PHP (some servers allow you to use different versions of PHP for each domain), so let’s say you want to use PHP5.5 Opcache then just create a file for this version, but you have another domain that uses PHP5.4 and this does not support the Opcache, because it requires PECL, an alternative solution that could use is the Xcache, then you can configure php5.4 with Xcache without conflicting with php5.5.

1

According to this website has as yes.

Just add that to your .htacess:

#configuração php
php_value  upload_max_filesize  10M

Also another good reference is here in this question of SOEN

  • 1

    There is a detail. This setting is only changed in Runtime if the server allows it. In Brazilian hosting for example, it is very difficult to do this. It is a PHP configuration that hosting imposes to prevent misuse.

0

  • The answer is interesting, but before you put an example make sure it works. I fixed it. Another note, ini_set will not work on all servers and probably has series of limitations through user permission level.

  • Not all properties of . ini work in ini_set().. To make sure which one you can use in ini_set(), you can access the following link and check which ones are accepted: https://www.php.net/manual/en/ini.list.php From the Changeable column together with the information from this link: https://www.php.net/manual/en/configuration.changes.modes.php You may know what and where the properties of . ini

Browser other questions tagged

You are not signed in. Login or sign up in order to post.