I have directory ‘upload/download’ in my project root. And I add controller/action - UploadController and actionDownload on it.
What I want is when user hit the url ‘/myproject/upload/download’ to execute controller action instead to open directory ‘upload/downlpoad’. I have to keep the same names.
This is probably something that needs to be done in a .htaccess file. If you only allow direct access to files (not directories), then Yii’s routing should kick in automatically.
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
Your best course of action is probably to put a separate .htaccess file inside the upload/download directory. I’ve done something similar for on demand thumbnail generation.
You’ll need to experiment with the content of the file. Something like this might work:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# If the requested file does not exist...
RewriteCond %{REQUEST_FILENAME} !-f
# forward to index.php
RewriteRule . index.php
</IfModule>
I’m not too familiar with .htaccess rules though, so I suspect you’ll need to do some more work on it.
The problem was that I load jquery with ‘registerCoreScript’. I change it to load from my file I put in application and now works. I don’t now why Yii::app()->clientScript->registerCoreScript(‘jquery’) doesn’t work.
To expand on something said above: I think the problem is that you have a directory AND a controller called ‘upload’ The .htaccess first looks to see is the user is requesting a file or directory that exists…THAN sends off to index.php.
Try changing the name of your ‘upload’ directory, or the structure to something like
Another option that I have seen quite often is to store the files in protected then use a proxy action to send to user. The link tag would call the controllerId/actionId passing an identifier to which file to send.