![](/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.