php - 在 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 文件已正常工作并已正确下载。
解决方案
推荐阅读
- reactjs - 如何将此功能组件转换为类
- google-sheets - 是否可以在 Google 表格中为每个用户的选定单元格设置权限?
- javascript - 如何在 GraphQL 中解析来自多个数据源的字段
- sql - RETURNING ... INTO:“INTO”处或附近的语法错误
- java - 填写笔记本
- python - 使用 Selenium 获取页面但等待未知元素值不为空
- lua - 令人敬畏的顽皮通知
- swiftui - 直接设置选择而不是从 viewModel 设置选择时,SwiftUI NavigationLink 行为不同
- python - 使用 python psycopg2 将 csv 数据插入 postgres 数据库的零长度分隔符错误
- scheme - 球拍中的矩阵操作