如何从另一个网站的WordPress上传文件夹中下载文件?

时间:2018-10-22 07:42:32

标签: php mysql wordpress download

我正在尝试使用WordPress数据库下载具有登录身份验证的文件,我正在使用以下代码从WordPress上载文件夹下载文件。但是很遗憾,我无法下载请求的文件,也没有错误消息。谁能帮助我解决此问题。

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 个答案:

没有答案