有时候不希望用户看到下载文件的地址。例如,付费购买后才能下载的文件,这个时候可以使用html页面表单直接提交的方式,调用php如下接口,就可以实现浏览器弹窗下载文件。
HTML代码
<!DOCTYPE html>
<html>
<head>
<title>下载</title>
</head>
<body>
<form action="/zcduibiao/download" method="post">
</form>
</body>
</html>
PHP代码
/**
* @param [string] $fileName [文件名称]
* @param [string] $fileUrl [文件地址]
*/
public function downloadFile($fileName,$fileUrl)
{
ob_end_clean();
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'. $fileName . '"');
header('Content-Transfer-Encoding: binary');
@readfile($fileUrl);
exit;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。