【问题标题】:Illustrator opening as PDFIllustrator 以 PDF 格式打开
【发布时间】:2009-12-31 09:13:06
【问题描述】:

我正在为我的办公室编写一个文件共享应用程序。我遇到的一个奇怪问题是,当您点击下载按钮时,Illustrator 文件以 PDF 格式打开。

这个问题是因为 Illustrator 文件的 mime 类型是application/pdf 而触发的。因此,浏览器在读取文件时,会触发 Acrobat 打开文件。有什么方法可以指示浏览器在 Illustrator 中打开文件?

或者有什么办法可以在上传文件后修改mime类型?后端代码是PHP。

感谢您的帮助。

【问题讨论】:

    标签: php file mime-types


    【解决方案1】:

    一种方法是强制浏览器显示“下载文件”对话框。因此用户可以决定如何处理该文件。

    这可以通过 PHP-Headers 来完成。 (http://www.php.net/manual/en/function.header.php#83384)

    还有一个关于如何做到这一点的示例(帖子 83384):

    <?php
        // downloading a file
        $filename = $_GET['path'];
    
        // fix for IE catching or PHP bug issue
        header("Pragma: public");
        header("Expires: 0"); // set expiration time
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        // browser must download file from server instead of cache
    
        // force download dialog
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
    
        // use the Content-Disposition header to supply a recommended filename and
        // force the browser to display the save dialog.
        header("Content-Disposition: attachment; filename=".basename($filename).";");
    
        /*
        The Content-transfer-encoding header should be binary, since the file will be read
        directly from the disk and the raw bytes passed to the downloading computer.
        The Content-length header is useful to set for downloads. The browser will be able     to
        show a progress meter as a file downloads. The content-lenght can be determines by
        filesize function returns the size of a file.
        */
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: ".filesize($filename));
    
        @readfile($filename);
        exit(0);
    ?>
    

    当使用这个例子时,请考虑使用

    $filename = $_GET['path'];
    

    是一个很大的安全问题。您应该改用 ID 之类的东西或验证输入。 例如:

    if($_GET['file'] == 1) {
        $filename = foobar.pdf;
    } elseif($_GET['file'] == 2) {
       $filename = foo.pdf;
    } else {
       die();
    }
    

    【讨论】:

    • 谢谢。我被带走了,以至于我没有想到要拨打readfile 电话。
    • 是的,除非Illustrator文件保存为Illustrator格式.ai,这是最好的解决方案。
    猜你喜欢
    • 2012-05-12
    • 1970-01-01
    • 2016-02-08
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    相关资源
    最近更新 更多