【发布时间】:2021-04-05 02:55:14
【问题描述】:
我只想将我的实时 sql 数据导出到特定目录中的 excel 文件中。我可以从 sql 下载 excel 文件,但它正在系统的下载文件夹中下载,但我想在实时服务器“/home/jw07sp1ptrfw/public_html/”上下载它,这是我在实时服务器上的目录。但是当我在运行此代码,它会在系统下载文件夹中下载文件 home_jw07sp1ptrfw_public_html_report.xls。如果有人可以提前感谢,请帮助我
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;
我也试过这个。但没有得到解决方案。
$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;
}
【问题讨论】:
标签: php directory content-disposition