首页 > 解决方案 > 在 wordpress 模板中使用 php readfile() 时出现空白页

问题描述

我有一个表格,用户填写他们的详细信息和序列号,然后下载软件安装程序,命名为他们的输入。例如serial.exe

提交表单后,我会检查文件是否存在,然后尝试下载文件:

    $directory = get_template_directory();
    $file = $directory . '/filename.exe';

    if (file_exists($file)) {

        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.$Serial.'.exe"');
        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));

        readfile($file);
        exit;
}

这会导致加载冻结,此代码下方没有任何内容被加载,但我看不到任何错误并且没有生成文件。

如果我将文件更改为 .png,则代码有效。

我还将相同的代码复制到 wordpress 之外的 php 页面,运行相同的代码并根据需要下载文件。

Wordpress 是否有可能以某种方式阻止 readfile() 请求,因为它是一个 .exe?

编辑:

这似乎是文件大小的问题,而不是文件类型的问题。

一个小的 .exe 文件已正常工作并已正确下载。

标签: phpwordpress

解决方案


推荐阅读