问题
I'm trying to change the size limit of an upload. I know I have to change those directive, in Apache configuration (some can't be changed using ini_set)
php_value session.gc_maxlifetime 3600
php_value max_input_time 3600
php_value max_execution_time 3600
php_value upload_max_filesize 10M
php_value post_max_size 110M
Unfortunately, I can't do that directly in a <Directory> of my virtualhost, since the directory is always the same (I'm using a front controller, thus all request go through index.php & are dispatched to the proper controller - I use Symfony)
My question, then, is how can I avoid this problem ? I don't want to set those values for the whole application, only for a specific action.
回答1:
This is possible, depending on how you map to your front controller. If you're doing it via rewrite rules then you can use a <Location> instead of <Directory> block to specify a chunk of path you want to change the settings for. <LocationMatch> lets you use a regexp for the same thing.
If all of your external URLs really start with /index.php? then consider setting up a redirect rule especially for these requests:
RewriteEngine on
RewriteRule ^foo/$ ^/index.php [L]
<Location /foo/>
php_value ...
</Location>
If that's not the case, you'll need to tell us more about your application structure.
回答2:
A possible workaround would be to create a directory with a single PHP file inside that implements your action and have the script that submits the POST target that file using a "custom" URL. After processing the input you would redirect back to a normal page through index.php. It's not clean, but it should work.
It could also be worth considering what exactly you stand to gain from this.
- it does not make any sense to set
session.gc_maxlifetimein just one action (especially if you are increasing it) - limiting
max_input_timeto one hour also does not make sense ifmax_execution_timeis also one hour max_execution_timecan be set at runtime- the other two directives cannot be set at runtime, but the POST size should not matter and the uploaded file size can be checked at runtime and handled accordingly
So, what's the aim here?
来源:https://stackoverflow.com/questions/10070585/php-ini-directive-per-directory-depending-of-request-uri