【问题标题】:After listing the uploaded files in the view how to view the listed files in browser codeigniter在视图中列出上传的文件后如何在浏览器codeigniter中查看列出的文件
【发布时间】:2018-07-29 07:07:32
【问题描述】:

我的控制器

    /*Task Attachment List*/
public function get_task_attachments()
{
    $task_id = $this->input->post('id',true);
    $attachment =  $this->technical_user_model->get_task_attachments($task_id);
  // echo json_encode($attachment);
   $output = null;

    foreach ( $attachment as $row)
   {
       //   here we build a dropdown item line for each
       // query result
      $path = $row['Attachment_Path'];
      $folder=$row['Project_Name'];
      $output .= "<li class='list-group-item'> <a target='_blank' href='download/$folder/$path' >".$row['Attachment_Path']."</a></li>";
   }
   echo $output;

}
/*Task Attachment List*/

我已经列出了上传的文件。如何在浏览器中查看而不是下载它。

【问题讨论】:

  • 你有哪些类型的文件 pdf、图片或其他?
  • 我正在上传各种文件,例如 .zip、doc、pdf、img、txt、ppt
  • doc pdf ppt & image 只会在浏览器中显示
  • ok..如何查看??
  • @Vignesh Thangavel 检查我的答案。

标签: jquery ajax codeigniter file-upload download


【解决方案1】:

在浏览器中只能查看有限的文件

.png, .pdf, .txt, .ppt, .doc

有些文件无法在浏览器中查看,但它们会像这样下载,

.zip, .rar, .exe

所以要在浏览器中查看文件,你可以使用类似的东西

&lt;a href="file_path" target="_blank"&gt;Click to view&lt;/a&gt;

【讨论】:

  • 只有图像正在打开。正在下载其他文件。
【解决方案2】:

您的服务器应返回此 http 标头:

Content-Type: application/pdf

为了在浏览器中查看,它还应该返回:

Content-Disposition: inline;filename="myfile.pdf"

【讨论】:

    猜你喜欢
    • 2015-11-11
    • 2018-11-15
    • 1970-01-01
    • 2014-11-23
    • 2012-04-10
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    相关资源
    最近更新 更多