Solution to the problem that php cannot download large files: first find and open the "php.ini" file; then set "memory_limit" to 1024M; then output the data to the client browser.
Recommended: "PHP Video Tutorial"
Solve the problem of being unable to download large files using PHP
In actual applications, there will be a size limit when using PHP's fread() function to read server files. When the server file size exceeds a certain amount (128M?), the client browser cannot download the file. Is it because of the memory_limit limit in the configuration file php.ini?
After setting the memory_limit to 1024M, I tested a 180M file and found that the problem remained. Code:
header('content-type:application/octet-stream'); header('accept-ranges: bytes'); header('content-length: '.filesize($filePath)); header('content-disposition:attachment;filename='.$fileName); $fp = fopen($filePath, "r"); echo fread($fp, filesize($filePath)); fclose($fp);
The above reading method is to output the data to the client browser at one time. Does it have anything to do with this? Try reading from the file line by line:
header('content-type:application/octet-stream'); header('accept-ranges: bytes'); header('content-length: '.filesize($filePath)); header('content-disposition:attachment;filename='.$fileName); $fp = fopen($filePath, "r"); while(!feof($fp)) { echo fgets($fp, 4096); } fclose($fp);
Aha! No problem anymore.
The above is the detailed content of What to do if php cannot download large files. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
