实现 目标另存为 的效果

来源:互联网 发布:淘宝订单贷款逾期 编辑:程序博客网 时间:2024/05/16 10:29

<?php

href="downfile.php?path=xxx"
===============
downfile.php

// We'll be outputting a flash

header('Content-type: application/x-shockwave-flash');

// It will be called downloaded.swf

Header("Content-Disposition: attachment; filename=".basename($path));

// The PDF source is in original.swf
readfile($path);

?>

在实现过程中,遇到的问题是保存完文件之后,打开没有内容,都是一片空白。后来发现是文件类型,以及readfile()函数的问题。

首先要注意到的是,在header 中给出文件类型。
Content-Type:
它定义了数据的类型,以便数据能被适当的处理。有效的类型有:text,image,audio,video,
applications,multipart和message。注意任何一个二进制附件都应该被叫做application/octet-
stream。这个头的一些用例为:image/jpg, application/mswork,multipart/mixed,这只是很少的
一部分。 例中application/x-shockwave-flash为flash格式。

另外需要注意的一点是,readfile()函数要给出完整的链接。即是绝对链接。刚开始没有读到文件,主要是使用了相对链接的关系。

 
原创粉丝点击