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.
How to use:
'import'=>array( 'application.extensions.*', ),
$this->widget('application.extensions.EFileCloaker', array( 'OriginalFileName'=>'Demo File', 'OriginalUrl'=>'../../file/demofile.pdf', ));
public function actionDownload() { $uncloak = new EFileCloaker(); // To get original Url for further processing // $originalUrl = $uncloak->getOriginalUrl(); // Downloads the file indicated by the $_GET key $uncloak->download(); // Or downloads the file while specifiying // some actions before actual downloads happens // with a callback function // $uncloak->download(function($key, $originalUrl) { // die($key . $originalUrl); // }); }
Total 20 comments
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.
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...
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.
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!!!
Thanks. that is great!
:-D
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.
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!
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?
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
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:
I specified there so that it would generate the url by the get format, not the path format.
As for the meaning of:
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:
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.
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?
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:
And at the root, I used another one with this rule:
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.
Cheers.
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.
Cheers
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 :)
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.
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.
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.
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.
Thanks
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 login to leave your comment.