dongpa9277 2014-01-03 15:19
浏览 138
已采纳

pdf下载文件名称问题

I am using the below code for secure pdf download. everything is working fine. the problem is downloaded pdf file name concats folder name also. I want to suppress the Folder name. Also provide any better solution for secured pdf downloads. Please check the below.

    $pdf_file = base64_decode($_GET['file_name']);
    $dir="Secured_files";
    $file = $dir."/".$pdf_file .".pdf";
    header("Content-Disposition: attachment; filename=" . urlencode($file));   
    header("Content-Type: application/octet-stream");

    header("Content-Type: application/download");
    header("Content-Description: File Transfer");            
    header("Content-Length: " . filesize($file));
    flush(); // this doesn't really matter.
    $fp = fopen($file, "r");
    while (!feof($fp))
    {
        echo fread($fp, 65536);
        flush(); // this is essential for large downloads
    } 
    fclose($fp);

file name is : here Secured_files is Folder name and xxxxx is file name.

Secured_filesxxxxx.pdf

  • 写回答

2条回答 默认 最新

  • doujing9972 2014-01-03 15:30
    关注
    $file_label = $pdf_file .".pdf";
    $file = $dir."/".$file_label;
    header("Content-Disposition: attachment; filename=" . urlencode($file_label));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验