您好,登录后才能下订单哦!
这篇文章给大家介绍使用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.'); 
} 
} 
?> 
关于使用php怎么对文件进行下载就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。