问题
I'm trying to set some htaccess rules for a specific Kohana controller. Basically its to do with form uploads. The majority of the site doesn't want to allow for large uploads so the php.ini will remain with the recommended settings.
However in one place a large file upload is required. I have the following options to add in my root .htaccess:
php_value max_input_time 60000
php_value post_max_size "1GB"
php_value upload_max_filesize "1GB"
php_value memory_limit "128MB"
But I don't know what to do to make it apply just for one controller (i.e. http://www.mysite.com/massiveupload).
Any help would be appreciated.
回答1:
There's also another solution. Again thanks to @LazyOne for the tip. This one is much neater, but it requires updating the Apache config directly (so you cannot deploy it on a shared hosting).
All you have to do is add this to your httpd.conf or vhosts.conf (inside <Directory>
or <VirtualHost>
as per Apache Docs).
<LocationMatch /massiveupload>
php_flag max_input_time 60000
php_value post_max_size 1024M
php_value upload_max_filesize 1024M
php_value memory_limit 128M
</LocationMatch>
Restart your server and it should just work!
Note, that although LocationMatch parses the /massiveupload
as a regular expression, we cannot use ^/massiveupload
(note the ^
char to match beginning of the string). This is because it will fail if you use a ModRewrite (which changes the final request url internally).
Note, you shouldn't make upload_max_filesize
and post_max_size
the exact same size, because if you upload a file that just reaches the upload_max_filesize
limit, any other post data will cause it to exceed the post_max_size
and the form submission will fail.
回答2:
What @LazyOne suggested is fairly easy to accomplish actually.
Consider this folder structure (only listing the most important files/folders):
application/
bootstrap.php
lib/
kohana-3.0.8/
modules/
system/
public_html/ <----- this is your DOCUMENT_ROOT
.htaccess
index.php
And consider you're using default Kohana's .htaccess:
RewriteEngine On
RewriteBase /
<Files .*>
Order Deny,Allow
Deny From All
</Files>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT]
- Now create an
upload/
folder in yourpublic_html/
. - Copy both
.htaccess
andindex.php
from your DOCUMENT_ROOT to theupload/
folder. Edit your
upload/.htaccess
: (only new changed lines displayed)php_flag max_input_time 86400 php_value post_max_size 1536M php_value upload_max_filesize 1024M RewriteEngine On RewriteBase /upload/ ... RewriteRule .* index.php/upload/$0 [PT]
Edit your
upload/index.php
and update all paths ($application, $modules, $system). You can download the whole tested packageCreate an upload controller.
Additionally you could split index.php into two parts (cut after defining the paths) so you don't duplicate the whole file.
Setup like this worked just well for me and you can download my test application from here: http://d.pr/ioYk
来源:https://stackoverflow.com/questions/6613143/kohana-controller-specific-htaccess