我正在为我的办公室编写一个文件共享应用程序。我正在经历的一个奇怪的问题是,当你点击下载按钮时,Illustrator文件在PDF中打开。
由于illustrator文件的mime类型为application/pdf,因此会触发此问题。因此,当浏览器读取该文件时,会触发Acrobat打开该文件。是否可以指示浏览器在Illustrator中打开该文件?
或者,有没有办法在上传文件后修改mime类型?后端代码是PHP。
谢谢你的帮助。
发布于 2009-12-31 17:24:30
一种方法是强制浏览器显示“下载文件”-dialog。这样用户就可以决定如何处理该文件。
这可以通过PHP-Header来完成。(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();
}https://stackoverflow.com/questions/1984633
复制相似问题