PHP 文件下载问题 - 无法读取

标签 php file download

我有以下自动下载文件的代码 单击提交按钮后,一切似乎都工作正常; 文件以正确的格式、正确的大小、正确的名称下载,但是当我 想要打开它,我收到错误,无法读取文件,可能是什么原因 有问题吗?

$file=mysql_fetch_assoc($sel);
$file=$file['downloadlink'];
header('Content-Type: "application/octet-stream"');
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment; filename=\"".basename($file)."\"");
readfile($file);

最佳答案

您可以尝试从 readfile() 注释中调整此函数:

function DownloadFile($file) { // $file = include path
    if(file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
}

关于PHP 文件下载问题 - 无法读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17319145/

相关文章:

http - IIS 文件下载挂起/超时 - sc-win32-status = 64

php - 从 CakePHP 组件到达 CakeRequest 对象

c# - 图像调整大小 asp.net mvc 应用程序

php - 在 Laravel 中获取每个用户的最新消息(行)

c - fread 是否移动文件指针?

java - 从文件中读取按钮名称

java - 如何从java中的php脚本强制下载文件?

编译 GitHub 上找到的编译器

php - 用php加密

php - 为什么 WordPress 仍然使用 addlashes()、register_globals() 和 magic_quotes?