php下载文件的代码示例
2015-01-24信息快讯网
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.');
}
}
?>
解析thinkphp的左右值无限分类
PHP 清空varnish 缓存的详解(包括指定站点下的)
PHP array_multisort() 函数的深入解析
PHP操作MongoDB GridFS 存储文件的详解
解析PHP中常见的mongodb查询操作
php代码书写习惯优化小结
浅析使用Turck-mmcache编译来加速、优化PHP代码
解析如何用php screw加密php源代码
解析如何在PHP下载文件名中解决乱码的问题
完美解决令人抓狂的zend studio 7代码提示(content Assist)速度慢的问题
具有时效性的php加密解密函数代码
深入理解curl类,可用于模拟get,post和curl下载
解决PHP超大文件下载,断点续传下载的方法详解
PHP多线程批量采集下载美女图片的实现代码(续)
PHP批量采集下载美女图片的实现代码
php列出一个目录下的所有文件的代码
PHP读取文件并可支持远程文件的代码分享
apache+codeigniter 通过.htcaccess做动态二级域名解析
PHP sprintf() 函数的应用(定义和用法)
php 对输入信息的进行安全过滤的函数代码
PHP删除数组中的特定元素的代码
PHP安全性漫谈
PHP连接SQLSERVER 注意事项(附dll文件下载)
php数组中删除元素的实现代码
php中使用接口实现工厂设计模式的代码
让PHP更快的提供文件下载的代码
php文件打包 下载之使用PHP自带的ZipArchive压缩文件并下载打包好的文件
Php中文件下载功能实现超详细流程分析
PHP备份数据库生成SQL文件并下载的函数代码
PHP判断搜索引擎蜘蛛并自动记忆到文件的代码
php代码收集表单内容并写入文件的代码
PHP中创建空文件的代码[file_put_contents vs touch]
php中强制下载文件的代码(解决了IE下中文文件名乱码问题)