php 下载保存文件保存到本地的两种方法_PHP教程

WBOY
Freigeben: 2016-07-20 11:15:35
Original
1084 Leute haben es durchsucht

第一种:

<span  1</span> <?<span php 
</span><span  2</span> <span function</span><span  downfile()
</span><span  3</span> <span {
</span><span  4</span> <span $filename</span>=<span realpath</span>("resume.html"); <span //</span><span 文件名</span>
<span  5</span> <span $date</span>=<span date</span>("Ymd-H:i:m"<span );
</span><span  6</span> <span Header</span>( "Content-type: application/octet-stream "<span ); 
</span><span  7</span> <span Header</span>( "Accept-Ranges: bytes "<span ); 
</span><span  8</span> <span Header</span>( "Accept-Length: " .<span filesize</span>(<span $filename</span><span ));
</span><span  9</span> <span header</span>( "Content-Disposition: attachment; filename= {<span $date</span>}.doc"<span ); 
</span><span 10</span> <span echo</span> <span file_get_contents</span>(<span $filename</span><span );
</span><span 11</span> <span readfile</span>(<span $filename</span><span ); 
</span><span 12</span> <span }
</span><span 13</span> <span downfile();
</span><span 14</span> ?>
Nach dem Login kopieren

<?<span php 
</span><span //</span><span 下载文件保存到本地
//www.jbxue.com</span>
<span function</span> downfile(<span $fileurl</span><span )
{
</span><span ob_start</span><span (); 
</span><span $filename</span>=<span $fileurl</span><span ;
</span><span $date</span>=<span date</span>("Ymd-H:i:m"<span );
</span><span header</span>( "Content-type: application/octet-stream "<span ); 
</span><span header</span>( "Accept-Ranges: bytes "<span ); 
</span><span header</span>( "Content-Disposition: attachment; filename= {<span $date</span>}.doc"<span ); 
</span><span $size</span>=<span readfile</span>(<span $filename</span><span ); 
</span><span header</span>( "Accept-Length: " .<span $size</span><span );
}
</span><span $url</span>="url地址"<span ;
downfile(</span><span $url</span><span );
</span>?>
Nach dem Login kopieren

<span  1</span> <?<span php 
</span><span  2</span> <span //</span><span 下载文件保存至本地
</span><span  3</span> <span //www.jbxue.com</span>
<span  4</span> <span function</span> downfile(<span $fileurl</span><span )
</span><span  5</span> <span {
</span><span  6</span> <span $filename</span>=<span $fileurl</span><span ;
</span><span  7</span> <span $file</span> = <span fopen</span>(<span $filename</span>, "rb"<span ); 
</span><span  8</span> <span Header</span>( "Content-type: application/octet-stream "<span ); 
</span><span  9</span> <span Header</span>( "Accept-Ranges: bytes "<span ); 
</span><span 10</span> <span Header</span>( "Content-Disposition: attachment; filename= 4.doc"<span ); 
</span><span 11</span> <span $contents</span> = ""<span ;
</span><span 12</span> <span while</span> (!<span feof</span>(<span $file</span><span )) {
</span><span 13</span> <span $contents</span> .= <span fread</span>(<span $file</span>, 8192<span );
</span><span 14</span> <span }
</span><span 15</span> <span echo</span> <span $contents</span><span ;
</span><span 16</span> <span fclose</span>(<span $file</span><span ); 
</span><span 17</span> <span }
</span><span 18</span> <span $url</span>="url地址"<span ;
</span><span 19</span> downfile(<span $url</span><span );
</span><span 20</span> ?>
Nach dem Login kopieren

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440197.htmlTechArticle第一种: ? = ("resume.html"); = ("Ymd-H:i:m" ( "Content-type: application/octet-stream " ( "Accept-Ranges: bytes " ( "Accept-Length: " . ( ( "Content-Disposition: attachment; f...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!