>php教程 >php手册 >PHP实现文件下载,

PHP实现文件下载,

WBOY
WBOY원래의
2016-07-06 14:24:54948검색

PHP实现文件下载,

<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> }

 

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.