将php值传递给href标签html

时间:2016-06-09 02:20:27

标签: php mysql codeigniter download

我想从数据库下载文件,但我有条件。每个文件都有唯一的request_id,即来自表格。以下代码是从上一个request_id下载的文件。例如,当我点击来自不同request_id的下载按钮时,它就像这样(在下载历史记录中):

  1. excel3.xlsx
  2. excel3(1)的.xlsx
  3. excel3(2)的.xlsx
  4. 应该是:

    1. excel1.xlsx
    2. excel2.xlsx
    3. excel3.xlsx
    4. 下载的文件是ZERO BYTE。因为没有显示错误,我找不到我的错误。请帮忙......

      下载按钮:

      <a href="<?php echo site_url('admin/download')?>" download>
        <button id="upload_excel" type="submit" class="btn btn-success" value=<?php echo $value['req']?>>
          <span class="glyphicon glyphicon-envelope" aria-hidden="true" ></span> Download
        </button>
      

      我的控制器:

      function download($req)
              {
                  $this->load->helper('download');
      
                  $this->load->model('request');
                  $data['file'] = $this->request->request($req);
                  foreach ($data['file'] as $key) 
                  {
                      $req_id = $key['req'];
                      $data['file'][$req_id] = $key['filename_user'];
                      $file = $data['file'][$req_id];
      
                      $download_file = FCPATH.'/kirim_undangan/';//path of the file
                      $content_type = mime_content_type($download_file);//mime type of the file
                      $file_name = basename($file);//file name based on request_id 
                      header("Pragma: public");
                      header("Expires: 0");
                      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                      header("Cache-Control: public");
                      header("Content-Description: File Transfer");
                      header("Content-type: ".$content_type);
                      header("Content-Disposition: attachment; filename=\"".$file_name."\"");
                      header("Content-Transfer-Encoding: binary");
                      header("Content-Length: ".filesize($download_file));
      
                          while (ob_get_level()) {
                             ob_end_clean();
                          }
                      readfile($download_file);
                  }
              }
      

      我的模特:

      function request()
          {
      
              $this->db->select("request_Id as req, email as email, name as nama, phone as phone, address as alamat_pengirim, filename_user, filename_admin");
              $this->db->where('status < 3');
              $query  =   $this->db->get('request');
              return $query->result_array();
          }
      

0 个答案:

没有答案