[PHP实例] PHP 强制文件下载

  1. /**
  2. * Downloader
  3. *
  4. * @param $archivo
  5. *  path al archivo
  6. * @param $downloadfilename
  7. *  (null|string) el nombre que queres usar para el archivo que se va a descargar.
  8. *  (si no lo especificas usa el nombre actual del archivo)
  9. *
  10. * @return file stream
  11. */http://m.nvzi91.cn/gongjingmilan/29374.html
  12. function download_file($archivo, $downloadfilename = null) {
  13.     if (file_exists($archivo)) {
  14.         $downloadfilename = $downloadfilename !== null ? $downloadfilename : basename($archivo);
  15.         header('Content-Description: File Transfer');
  16.         header('Content-Type: application/octet-stream');
  17.         header('Content-Disposition: attachment; filename=' . $downloadfilename);
  18.         header('Content-Transfer-Encoding: binary');
  19.         header('Expires: 0');
  20.         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  21.         header('Pragma: public');
  22.         header('Content-Length: ' . filesize($archivo));
  23. http://m.nvzi91.cn/gongjingxirou/29375.html
  24.         ob_clean();
  25.         flush();
  26.         readfile($archivo);
  27.         exit;
  28.     }
  29. http://m.nvzi91.cn/gongwaiyun/29376.html
  30. }m.nvzi91.cn
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值