PHP ini directive per directory depending of request_uri

那年仲夏 提交于 2019-12-10 17:20:40

问题


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_maxlifetime in just one action (especially if you are increasing it)
  • limiting max_input_time to one hour also does not make sense if max_execution_time is also one hour
  • max_execution_time can 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!