分享---PHP下载文件的两种方法

巴扎黑
Libérer: 2016-11-12 10:46:42
original
1397 Les gens l'ont consulté

PHP下载文件的两种方法与代码。

分享PHP实现下载文件的两种方法。分享下,有用到的朋友看看哦。

方法一:

<?php
/*** 下载文件* header函数**/header(&#39;Content-Description: File Transfer&#39;);
header(&#39;Content-Type: application/octet-stream&#39;);
header(&#39;Content-Disposition: attachment; filename=&#39;.basename($filepath));
header(&#39;Content-Transfer-Encoding: binary&#39;);
header(&#39;Expires: 0′);header(&#39;Cache-Control: must-revalidate, post-check=0, pre-check=0′);
header(&#39;Pragma: public&#39;);
header(&#39;Content-Length: &#39; . filesize($filepath));
readfile($file_path);
?>
Copier après la connexion

以上代码用到了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(&#39;Content-type: application/x-&#39;.$fileinfo[&#39;extension&#39;]);
header(&#39;Content-Disposition: attachment; filename=&#39;.$fileinfo[&#39;basename&#39;]);
header(&#39;Content-Length: &#39;.filesize($filename));
readfile($thefile);exit();
?>
Copier après la connexion


source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!