Yii 1.1: efilecloaker

Cloak your files link from end users.

This extension is a simple implementation to cloak your original location of files to be downloaded. That way, no direct links to your file will be available to visitors.


  • Yii 1.1.6 or above
  • mod_xsendfile (optional) to allow download of large files with ease


How to use:

  • Download and extract EFileCloaker in your extension directory.
  • Modify your configuration file to auto import the extension folder example:
  • Call the widget with parameters: (1) OriginalFileName as displayed name; (2) OriginalUrl as direct link to file. Example:
       $this->widget('application.extensions.EFileCloaker', array(
           'OriginalFileName'=>'Demo File',
  • Create an action to download files. Example:
    public function actionDownload()
        $uncloak = new EFileCloaker();
        // To get original Url for further processing
        // $originalUrl = $uncloak->getOriginalUrl();
        // Downloads the file indicated by the $_GET key
        // Or downloads the file while specifiying
        // some actions before actual downloads happens
        // with a callback function
        // $uncloak->download(function($key, $originalUrl) { 
        //  die($key . $originalUrl); 
        // });
  • Done

Total 20 comments

#8803 report it
Blue Spy at 2012/06/27 05:31pm

Hi jzhong5,

I agree, sometimes it's not reliable. Try to use the latest version of the component. I add a method getCallingUrl() which returns the page where the widget is placed.

Try it, I hope it satisfies your need.

#8791 report it
jiaming at 2012/06/26 10:49pm
It may not be reliable

Hi, I know $_SERVER['HTTP_REFERER'], but it may not be reliable....As some browsers just send blank string for it or even not send at all....So it's not a good idea to get the previous page's url...

It is wired each time i use loadModel in the actionDownload it gives me 404 error...

#8790 report it
Blue Spy at 2012/06/26 05:41pm
http referer

I'm doing fine, thanks :) That's good news to know your application is going to be launched soon, congratulations.

If I were to rephrase your question, would it be the same as: "How to get the page calling the download file?" If it is so, you could try using $_SERVER['HTTP_REFERER'], do some google to know more about it. Since it's already in a global variable, I didn't include it in the extension.

I did, however, push another update of the extension allowing to use closures to execute a function exactly before it downloads the file. Check the extension page above for details.

#8778 report it
jiaming at 2012/06/26 10:15am
About get the id of the view page

Hi, how are you doing these days. My application is gonna launch next month and I meet a new problem about downloading. For example. I do have a download button in the view page... http://www.123.com/topic/22 and the download link would be http://www.123.com/topic/download/sfa21fsf

Is there a way I can get the id(in this case 22) of the previous view page?

since the path of the download page does not contain id so I can't just use loadModel in the actionDownload of TopicController...

I want to collect how many times the file has been downloaded...so I need to get the id of that topic....

Thanks so much!!!

#8411 report it
jiaming at 2012/05/31 11:44pm
That's great. thank you.

Thanks. that is great!


#8410 report it
Blue Spy at 2012/05/31 08:06pm

Thats great :)

What I meant by directly from the file system is by accessing the local path.

For web files, they usually have several paths that we could use to access them. The one I meant by URL would be a path like -> http://www.example.com/some/path/to/file while a filesystem path i meant would be something like -> /usr/global/www/some/path/to/file

I hope that clears your confusion.

#8397 report it
jiaming at 2012/05/31 02:08am
Thanks so much .

Works like a charm.

Thanks so much for your extension and your help!!!!!!!

Would you mind explaining a little bit about " but from the file system."

So you are getting the path from the database directly?

Anyway, it's such a great extension! and xsendfile works properly now!

#8396 report it
Blue Spy at 2012/05/31 12:40am
Another fix

Hi jzhong5,

after i and some of my friends tested it out, the reason of the xsendfile might not be the index.php. After some testing and debugging, the more likely cause is the path generated is to relative and since url_rewrite do some manipulation in the url path, the relative path seems to get affected.

I've changed the way for it to take the path so that it would take it directly not by URL, but from the file system.

Would you mind testing the new version of it and see how it works with you?

#8360 report it
jiaming at 2012/05/29 12:12am
Thanks so much

In your website...

your download link is:


So you put your index.php right after demo_efc

however, in mine...

the download link is


Where should I put the index.php....? Why is the download path so different....?

Sorry about so many problems...

Thanks so much!

Best, jiaming

#8358 report it
Blue Spy at 2012/05/28 07:15pm
Confirm the index.php on your code

Yes, it's supposed to have index.php on the download part. I specifically made it to be like that for the extension. Look at the code to see what I mean:

Yii::app()->urlManager->showScriptName = true;

I specified there so that it would generate the url by the get format, not the path format.

As for the meaning of:

RewriteRule . /demo_efc/index.php

It just simply changes the current path (eg. http://expressthisout.com/demo_efc/site/index/) to include the index.php (eg. http://expressthisout.com/demo_efc/index.php/site/index/)

If i just use:

RewriteRule . index.php

The path would be translated from http://expressthisout.com/demo_efc/site/index/ to http://expressthisout.com/index.php/site/index/ which would most likely return an error of 404.

#8349 report it
jiaming at 2012/05/28 07:51am
Thanks for your reply

RewriteRule . /demo_efc/index.php

Would you please explain a little bit about what this line for?

Your website works fine because when I download the file, the index.php will appear in your url....but mine is not.

Do I need to add some similar lines like this?

#8345 report it
Blue Spy at 2012/05/28 12:44am
Seems okay

Actually I'm using similar rules like yours. I tried it here -> http://expressthisout.com/demo_efc/site/index/ and it seems fine.

This is the rule i'm using:

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 . /demo_efc/index.php

And at the root, I used another one with this rule:

# Remove www
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
#8333 report it
Blue Spy at 2012/05/27 01:40am
x-sendfile fix

Hi jzhong5,

I couldn't really find out what cause the unexpected behavior, but I did implement a tweak to make it work. I've tested it on my system and it seems that xsendfile works quite well with mod_rewrite on my system.

Do give it a try.


#8282 report it
jiaming at 2012/05/22 08:10pm
thanks for your reply

Looking forward to hearing from you! The problem is because my rewrite rule will erase all index.php in the url...

Anyway....I will post the bootstrap codes later. it's pretty simple.

Thanks for your amazing ext.


#8278 report it
Blue Spy at 2012/05/22 01:20pm
Back again

Hi, sorry to be back after a while. Lifes been crazy lately.

I haven't actually tried to use the mod_rewrite with the extension. Thanks for the info, I'll see what I can do about it in a while.

Hope to reach you back soon.

PS: Thanks if you did. Would like to see the updated code :)

#8173 report it
jiaming at 2012/05/14 05:26pm
A bug about xsendfile

Is there any chance i can use RewriteEngine to get rid of index.php and use xsendfile at the same time...?

Each time, I use my rewriteEngine, xsendfile gives me index.php not found.

So wired...

If this can not be fixed...We can't use xsendfile....

Any ideas?

PS: I just bootstrapped your ext. I will send you the codes later.

#8163 report it
Blue Spy at 2012/05/14 01:54am

Are you sure it is the right path? To be sure, the path is supposed to be a relative path towards the root directory.

Unfortunately, no. I haven't made an option to change how it looks. I'll note that as a future feature. As for now, you may edit how it looks like by editing directly the code under the function _createMarkup.

#8162 report it
jiaming at 2012/05/13 09:05pm

Sorry but still not work. This time it keeps giving me file not found. I can sure it's ok with my path. I tested my path with the normal download link.

#8161 report it
jiaming at 2012/05/13 08:28pm

thank you for your quick fix. I will try it tonight when I get home.

Also, is there any chance that I can use your ext and do NOT just display a filename? Instead, a button? or I can use buttons in bootstrap?

Shall I use beginWiget .. or something like that?

Anyway I will give you a report about this version this night.


#8158 report it
Blue Spy at 2012/05/13 04:49pm
Path URL issue.

As I checked further in, it seems the issue there is the path url type which wasn't anticipated in my previous version of the extension. As for now, I did a little update to fix the issue.

I hope this fix the issue you are facing, jzhong5.

Leave a comment

Please to leave your comment.

Create extension