dongwen5336 2016-06-29 06:20
浏览 588
已采纳

标题(“Content-Type:application / zip”)和标题(“Content-Disposition:attachment; filename = $ fileName”)在wordpress中不起作用?

enter image description hereThe above two function not working in wordpress. I want to download file and i am running wordpress in xampp also i have tried it in another online server with wordpress framework still not working.

but this is working in another online server where i have not used wordpress framework.

Is there is problem with wordpress using the above two function?

(below code just take get request which is the path to the file to be downloaded from the server and after validating token the path is given from database)

<?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";

?>
  • 写回答

1条回答 默认 最新

  • douhao2026 2016-06-29 06:30
    关注

    first of all lets verify my assumption is correct. In the wordpress index.php file, right at the top add this ( obviously after the <?php tag though )

    ini_set('display_errors', -1 );
    

    Let me know what that says when you try to download the file.

    SQL Injection would let me do this with your url

     $token="'; SELECT * FROM wp_token_table WHERE 1 LIMIT 1; --";
    

    And then your query would be this

    "SELECT * FROM wp_token_table WHERE token=''; SELECT * FROM wp_token_table WHERE 1 LIMIT 1; --'"
    

    The -- is start of comment to discard the ending ' then i would essentially select the first entry from that table. Or worse.

    It's very important to prevent that.

    For the error, I would do this

     <?php
      echo "hello";
      /* -- rest of code */
    

    And make sure the page works first. Once you know that you can rule out problems with the url, then uncomment bits of the code tell it breaks. That will show you where the error is. Unfortunately error reporting wont generally work if its on a page with a syntax error, because php cant even parse the page, so it cant run anything on it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退