0

我不明白我一直在阅读的文档。任何人都可以在这里解释如何做到这一点?

我有一个指向函数 showFile() 的 HTML 链接。有两个获取,一个 id,它是文件名,一个 ext,文件的扩展名。(只有扩展名将是 pdf、jpg 和 gif)我正在使用 codeigniter framwework btw。

我阅读了有关标题的内容,但是当我尝试它时,它只是下载了文件。任何帮助,将不胜感激。

功能至今---------

 public function showFile () {
    $fileId = $this->input->get('id');
    $fileExt = $this->input->get('ext');

}
4

2 回答 2

3

在 HTML 中是这样的:

<a href="downloadfile.php?filesrc=blah.pdf" target=_new>
    Click here to download blah.pdf</a>

当然,href 必须echo在 PHP 中编辑。

<a href="downloadfile.php?filesrc=<?php echo $filepath ?>" target=_new> ... </a>

哦,downloadfile.php 将简单地header('...');重定向到该文件。

于 2012-04-20T21:34:49.827 回答
3
class Files extends CI_Controller{

    public function show_file($id, $ext){
       $file_location = '';
       switch($ext){
           case 'pdf':
             $file_location = 'location-to_pdf_files'; // store as constant maybe inside index.php - PDF = 'uploads/pdf/';

             //must have PDF viewer installed in browser !
          $this->output
           ->set_content_type('application/pdf')
           ->set_output(file_get_contents($file_location . '/' . $id . '.pdf'));

           break;
           //jpg gif etc here...
       }

    }
}

-

$route['view/(:any)/(:any)'] = 'files/show_file/$1/$2';

-

<a href="<?php echo site_url('view/picture/pdf');?>" rel="nofollow" target="_blank">Some_file<a/>
于 2012-04-22T00:12:44.417 回答