首页  >  文章  >  后端开发  >  init.php文件 PHP实现文件下载

init.php文件 PHP实现文件下载

WBOY
WBOY原创
2016-07-28 08:29:411010浏览

<span> 1</span><span>public</span><span>function</span><span> get_download_file()
</span><span> 2</span><span>{
</span><span> 3</span><span>header</span> ( 'Content-Description: File Transfer'<span> );
</span><span> 4</span><span>header</span> ( 'Content-Type: application/octet-stream'<span> );
</span><span> 5</span><span>header</span> ( 'Content-Disposition: attachment; filename=' . <span>basename</span> ( <span>$file</span><span> ));
</span><span> 6</span><span>header</span> ( 'Content-Transfer-Encoding: binary'<span> );
</span><span> 7</span><span>header</span> ( 'Expires: 0'<span> );
</span><span> 8</span><span>header</span> ( 'Cache-Control: must-revalidate'<span> );
</span><span> 9</span><span>header</span> ( 'Pragma: public'<span> );
</span><span>10</span><span>header</span> ( 'Content-Length: '  .  <span>filesize</span> ( <span>$file</span><span> ));
</span><span>11</span><span>ob_clean</span><span> ();
</span><span>12</span><span>flush</span><span> ();
</span><span>13</span><span>readfile</span> ( <span>$file</span><span> );
</span><span>14</span><span>exit</span><span>;
</span><span>15</span> }

以上就介绍了init.php文件 PHP实现文件下载,包括了init.php文件方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn