![](/img/trans.png)
[英]PHP Content-Disposition header: Specialcharacters in the filename
[英]header(“Content-Type: application/zip”) and header(“Content-Disposition: attachment; filename=$fileName”) not working in wordpress?
以上两个功能在wordpress中不起作用。 我想下载文件,并且我在xampp中运行wordpress,我也曾在另一台在线服务器中尝试过它,而wordpress框架仍然无法正常工作。
但这在另一个我没有使用wordpress框架的在线服务器上工作。
使用上述两个功能的wordpress是否有问题?
(下面的代码只接受get请求,这是要从服务器下载的文件的路径,并且在验证令牌后,该路径是从数据库给出的)
<?php
ini_set('display_errors', -1 );
require('wp-blog-header.php');
require('wp-config.php');
$token = ($_GET["token"]);
$platform = ($_GET["platform"]);
$resolution = ($_GET["resolution"]);
$assetName =($_GET["assetName"]);
$currentTime = date("ymdHi" , time());
if($wpdb->query("SELECT * FROM wp_token_table WHERE token='$token'")){
$result = $wpdb->get_results("SELECT (path) FROM wp_path_table WHERE os='$platform' AND res = '$resolution' AND bundle_name= '$assetName'");
if($result){
$path = $result[0]->path;
$fileName = basename($assetName);
$filePath = $path;
if(!empty($fileName) && file_exists($filePath)){
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/zip");
header("Content-Length:".filesize($filePath));
header("Content-Disposition: attachment; filename=$fileName");
header("Content-Transfer-Encoding: binary");
readfile($filePath);
exit;
}
}
}else echo "false";
?>
首先让我们验证我的假设是正确的。 在wordpress index.php文件中,在顶部添加此名称(尽管明显在<?php
标记之后)
ini_set('display_errors', -1 );
让我知道您尝试下载文件时的提示。
SQL注入将允许我使用您的网址执行此操作
$token="'; SELECT * FROM wp_token_table WHERE 1 LIMIT 1; --";
然后您的查询将是这样
"SELECT * FROM wp_token_table WHERE token=''; SELECT * FROM wp_token_table WHERE 1 LIMIT 1; --'"
--
是注释的开头,以丢弃结尾的'
那么我实质上将从该表中选择第一个条目。 或更糟。
防止这种情况非常重要。
对于错误,我会这样做
<?php
echo "hello";
/* -- rest of code */
并确保页面首先生效。 一旦知道可以排除url的问题,那么代码的未注释位便表明它已中断。 这将向您显示错误所在。 不幸的是,错误报告通常无法在语法错误的页面上运行,因为php甚至无法解析该页面,因此它无法在页面上运行任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.