首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Illustrator以PDF格式打开

Illustrator以PDF格式打开
EN

Stack Overflow用户
提问于 2009-12-31 17:13:06
回答 1查看 533关注 0票数 2

我正在为我的办公室编写一个文件共享应用程序。我正在经历的一个奇怪的问题是,当你点击下载按钮时,Illustrator文件在PDF中打开。

由于illustrator文件的mime类型为application/pdf,因此会触发此问题。因此,当浏览器读取该文件时,会触发Acrobat打开该文件。是否可以指示浏览器在Illustrator中打开该文件?

或者,有没有办法在上传文件后修改mime类型?后端代码是PHP。

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-12-31 17:24:30

一种方法是强制浏览器显示“下载文件”-dialog。这样用户就可以决定如何处理该文件。

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

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

代码语言:javascript
复制
<?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);
?>

在使用此示例时,请考虑使用

代码语言:javascript
复制
$filename = $_GET['path'];

是一个很大的安全问题。你应该使用像ID这样的东西,或者验证输入。例如:

代码语言:javascript
复制
if($_GET['file'] == 1) {
    $filename = foobar.pdf;
} elseif($_GET['file'] == 2) {
   $filename = foo.pdf;
} else {
   die();
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1984633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档