分享---PHP下載文件的兩種方法

PHP下載文件的兩種方法與代碼。

分享PHP實現下載文件的兩種方法。分享下,有用到的朋友看看哦。

方法一:

<?php

/**
* 下載文件
* header函數
**/header('Content-Description: File Transfer');header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename='.basename($filepath));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($filepath));readfile($file_path);?>

以上代碼用到了php header函數,可以參考以下如下的文章:
php header()函數的簡單例子
php header函數實現文件下載的實例代碼
php中header函數的用法舉例詳解
php header 使用詳解
php header函數 文件下載時直接提示保存的代碼
php header函數實現文本文件下載的方法
php 文件頭部(header)信息詳解
php使用header發送各種類型文件下載的例子

瞭解php中header函數的用法。

方法二:

<?php//文件下載
//readfile$fileinfo = pathinfo($filename);header('Content-type: application/x-'.$fileinfo['extension']);header('Content-Disposition: attachment; filename='.$fileinfo['basename']);header('Content-Length: '.filesize($filename));readfile($thefile);exit();?>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章