简体   繁体   中英

How to change directory of Content-Disposition in php

I just want to export my live sql data into excel file inside specific directory. I am able to to download the excel file from sql but it is downloading in download folder in sytem but i want to download it on live server "/home/jw07sp1ptrfw/public_html/" this is my directory on live server.But when I am running this code its downloading the file home_jw07sp1ptrfw_public_html_report.xls in system download folder. Please help me if any one can thanks in advance

 include('config.php');
    $html='<table> <tr><td> Name</td><td>Email</td><td>Phone</td></tr>';
    
      $result = mysqli_query($link,"SELECT * FROM `order`");
                              while($row = mysqli_fetch_assoc($result))
                                    {
    
    $html.='<tr><td>'.$row["name"].'</td><td>'.$row["email"].' </td><td> '.$row["phone"].'</td></tr>';
    
                                    }
                                    
    $html.='</table>';
    header('Content-Type: application/xls');
    header('Content-Disposition: attachment; filename= /home/jw07sp1ptrfw/public_html/report.xls');
     echo $html;

I have also tried this. But not getting the solution.

$file_name = "report.xls";

$rootDir = realpath("/home/jw07sp1ptrfw/public_html");
$fullPath = realpath($rootDir . "/" . $file_name);

// if ($fullPath && is_readable($fullPath) && dirname($fullPath) === $rootDir) 
{
    
    header('Content-Type: application/xls');
    header('Content-Disposition: attachment; filename=' . basename($fullPath));
    readfile($fullPath);
     echo $html;
}

You can't do that. The filename is just a hint to the browser, and it will preprocess it for security reasons. See https://greenbytes.de/tech/webdav/rfc6266.html#disposition.parameter.filename .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM