gpt4 book ai didi

php - 该代码用于下载excel文件(.xls)

转载 作者:搜寻专家 更新时间:2023-10-31 21:13:04 25 4
gpt4 key购买 nike

问题: 下载后,文件不包含数据。 即它变成空白。

所以请帮助我。

<?php

session_start();
include_once 'oesdb.php';
$id=$_REQUEST['id'];

if(isset($_REQUEST['id']))
{
$sql=executeQuery("SELECT * FROM file where id=$id");
$rows = mysql_fetch_array($sql);
$file =$rows['file'];


header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile('uploads/'.$file);
exit;

}
?>

最佳答案

为什么不在上传文件夹中创建一个 HTACCESS 文件然后说明

    Allow From 127.0.0.1
Deny From All

然后只需创建一个 URL,使用 HTML5 的新下载功能,执行如下操作:

    <a href="uploads/filenamehere.txt" download="filenamehere.txt">click to download</a>

它可以节省尝试使用 PHP 制作下载脚本的时间。

关于php - 该代码用于下载excel文件(.xls),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14913646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com