Greetings, I have a folder with many pdf files. What i want is to be able to generate links in a view, and when i click one of those links the browser render's the file. In last case, at least the browser downloads the file to the hard-drive. Neither of both could implement.
For now i have this code in my index.php file. It sets the pdfs folder and list the files in my browser window because of the foreach loop.
<?php
$cfileDir = Yii::app()->file->set('pdfs/');
$ficheiros = $cfileDir->getContents();
if (isset($ficheiros[0])) {
foreach ($ficheiros as $index => $ficheiro) {
$nomeFicheiro = substr($ficheiro, strrpos($ficheiro, '/') + 1);
echo CHtml::link($nomeFicheiro, array('pdfs/'.$nomeFicheiro)) . "<br/>";
}
} else {
echo "Não existem ficheiros disponíveis para download.";
}
?>
This code shows the links generated for each file inside the folder PDFS, but when i click on a link it display ERROR 404 could not resolve the requisition "pdfs/nameoffile.pdf". I don't have any code im my Controller, is it needeed ? I use the extension Cfile and its methods to manage files, but i don't think it as influence on the ERROR 404.
**
What to do... Any solutions ? Thanks in advance.
**