zoukankan      html  css  js  c++  java
  • php下载文件的代码示例

    <?php
    $file = 'monkey.gif';
     
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
    ?>
    

     以上代码是下载代码

    接下来贴一段在线预览pdf文件的代码

    <?php
        public function fddAction()
        {
            // get attachment location
            $attachment_location = $_SERVER["DOCUMENT_ROOT"] . "/pdf/fdd/sample.pdf";
            
            if (file_exists($attachment_location)) {
                // attachment exists
                
                // send open pdf dialog to user
                header('Cache-Control: public'); // needed for i.e.
                header('Content-Type: application/pdf');
                header('Content-Disposition: inline; filename="sample.pdf"');
                readfile($attachment_location);
                die(); // stop execution of further script because we are only outputting the pdf
                
            } else {
                die('Error: File not found.');
            }
        }
    ?>
    

      未完待续

  • 相关阅读:
    P2422 良好的感觉
    拉格朗日插值
    C# 中的委托和事件(详解)
    异步委托
    ManualResetEvent详解
    快速理解C#高级概念事件与委托的区别
    拉格朗日多项式
    oracle 插入一个从别处查询获得字段的值
    decode和nvl的用法
    C#将像素值转换为图片
  • 原文地址:https://www.cnblogs.com/MRPUNK/p/2569334.html
Copyright © 2011-2022 走看看