下载器代码可能有问题,导致PDF文件损坏
服务器中的PDF文件是健康的:通过FTP直接下载来验证过。
下载器的部分代码如下:
$file_size = filesize($filedir);
header("Content-type: application/octet-stream;charset=ISO-8859-1");
header("Cache-control: private");
header("Accept-Ranges: bytes");
header("Accept-Length: ".$this->FjSize);
header("Content-Disposition: attachment; filename=" . $this->delFileName);
$fp = fopen($filedir,"r");
$buffer_size = 1024;
$cur_pos = 0;
while(!feof($fp) && $filedir-$cur_pos > $buffer_size)
{
$buffer = fread($fp,$buffer_size);
echo $buffer;
$cur_pos += $buffer_size;
}
if($file_size > 0)
$buffer = fread($fp,$file_size-$cur_pos);
else
$buffer = fread($fp,$this->FjSize);
echo $buffer;
fclose($fp);
flush();
回复讨论(解决方案)
$fp = fopen($filedir,"r b"); //二进制方式打开,虽然 linux 不需要,但仍建议这么做
文本方式打开的文件,0x1a 就视为文件尾了
while(!feof($fp) && $filedir-$cur_pos > $buffer_size)
宜写作
while(!feof($fp))
feof($fp) 就是文件尾了
再 $filedir-$cur_pos > $buffer_size 已无必要
双重判断可能导致失误,比如 $filedir 不是 $buffer_size 整数倍时
另外,除文件内容外,不能输出任何其他内容,包括 BOM 头
按照版主说的改了。照样出错。
PS:程序过去一年都运行良好,最近几天才出问题。
上传了一个文件,内容如下
1234567890
abcdefghijklmnopqrstuvwxyz
然后下载到本地,结果如下
? 2426153钒4噱JLJNIMK先淌紊退/(,*.)-+?? ?? ??&

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

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
