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

k97glaaz  于 2021-06-19  发布在  Mysql
关注(0)|答案(0)|浏览(281)

我试图下载一个文件与登录验证使用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;
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题