douzi1991 2018-10-22 07:42
浏览 84

如何从其他网站下载WordPress上传文件夹中的文件?

I am trying to download a file with login authentication using WordPress database, I am using the below code to download file from WordPress upload folder. But unfortunately, I am unable to download the requested file and no error message. Can any one help me to fix this issue.

if (isset($_GET['downloadfile'])) {
    $posts_id = $_GET['downloadfile'];
    $sql_app = $auth_user->runQuery("
        SELECT DISTINCTROW AA.post_id, 
            BB.`meta_value` AS 'resume' 
        FROM `wp_postmeta` AS AA 
        LEFT OUTER JOIN `wp_postmeta` AS BB ON AA.post_id = BB.post_id 
            AND BB.meta_key ='resume'
        WHERE AA.meta_key IN ('resume')
            AND AA.post_id=:posts_id
            GROUP BY AA.post_id
            ORDER BY AA.post_id DESC
    ");
    $sql_app->execute(array(":posts_id"=>$posts_id));
    $downRow=$sql_app->fetch(PDO::FETCH_ASSOC);

    $filepath = $downRow['resume'];
    // Process download
    if(file_exists($filepath)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($filepath));
        flush(); 
        readfile($filepath);
        exit;
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c++ gmssl sm2验签demo
    • ¥15 关于模的完全剩余系(关键词-数学方法)
    • ¥15 有没有人懂这个博图程序怎么写,还要跟SFB连接,真的不会,求帮助
    • ¥15 关于移动机器人坐标计算
    • ¥30 模拟电路 logisim
    • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
    • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
    • ¥15 安装quartus II18.1时弹出此error,怎么解决?
    • ¥15 keil官网下载psn序列号在哪
    • ¥15 想用adb命令做一个通话软件,播放录音