I’m setting up a list of product on my website using yiiframework.
These products are managed with subdirectories containing images and downloadable pdf files.
I can put images on webproject/images/ to simplify my work but I would like the downloadable files would be put in proteced/site/pages/products with the chance to make them downlaodable after the login or accessing them just through the website (I still must decide it).
the page that will call xSendFile is placed in /protected/views/site/myfile.php
the PDF file is placed in /protected/views/site/files/myPDFfile.pdf
My first attempt, in myfile.php was:
<a href="'.Yii::app()->request->xSendFile("/files/myPDFfile.pdf",array(
"mimeType"=>"application/pdf",
"terminate"=>false)).'">Click here to download myfile</a>
But it doesn’t work.
How can I make it downloadable through a clickable link?
You need to give the proper path to xSendFile, relative path do not work for this method… but note that what you wrote above is not even a relative path…
the problem is that I won’t have my own server to run this website (it’s a website based on Yii, not a real web-application) so it will be stored in a simple web hosting service.
I think I must have posted this in the past, though I can’t recall where or when.
So I posted it again on github:
I perfected this script over a period of several years - it deals with a number of problems that are hard to get around, and has been used on numerous sites.
It supports download managers and multi-threaded downloads and HTTP resume; it stream out the data in segments rather than using a chunk of memory as large as the file you’re sending; it reports (under Apache) whether the file was fully downloaded and received by the user, so you can track/count downloads for security purposes.
All of those features are missing in CHttpRequest::sendFile() which in my opinion is much too basic. As I recall, I’ve encouraged the framework team to adopt my implementation in the past, but they weren’t interested - I don’t recall why…