douyun1546 2017-08-18 16:46
浏览 77

下载的pdf文件无法打开 - 编码不当?

I'm unsure how to approach solving this problem. I have a link that when clicked downloads the file to the users machine. The file is a pdf. If I copy and paste the file onto the desktop and then open that copy, it works perfectly fine. Yet when the user downloads and tries to open, I get this:

enter image description here

Here is the code:(fyi: i have validation on the filename before this..)

$file_name = $dat->filename; //'file.avi';
    $file_url = $dat->path . $dat->url . $filename; 
    header('Content-Type:'. $dat->type);
    header("Content-disposition: attachment; filename=\"" . $file_name . "\"");
    header("filename=\"" . $file_name . "\"");
    readfile($file_url);
    exit;

I have tried multiple headers but nothing seems to work. What am I doing wrong with this encoding? Seems to me that the file is valid and should be a simple copy to the users machine just like the copy I made locally worked just fine.

Update

I opened the file as per Marcin's suggestion, in Sublime. This is what I get.. no body?

<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="/assets/jQuery/jquery-ui-1.12.1/jquery-ui.min.css">
    <script src="/assets/jQuery/jquery-3.2.1.min.js"></script>
    <script src="/assets/jQuery/jquery-ui-1.12.1/jquery-ui.min.js"></script>
    <script src="/assets/pdfObject/pdfObject.js"></script>
    <style>
        body{
            overflow: hidden;
        }
        .pdfobject-container {
            height: 99vh;
            overflow: hidden;
        }
    </style>
    <title></title>
</head>
    <body>
  • 写回答

1条回答 默认 最新

  • douli2876 2017-08-18 16:51
    关注

    I'd open the file in i.e. text editor or binary editor and see what's inside. My blind guess you is that you will find there some sort of i.e. PHP notice/error message or something polluting the data other way.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据