php 下载保存文件保存到本地的两种方法_PHP教程
第一种:
<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> ?>
<?<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>?>
<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> ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
