1

到目前为止,我尝试过的可以下载 sql 文件,但它是空的

//test.php

 <?php
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename=wordpress_db1.sql');
?>

这是我的根文件夹的样子

在此处输入图像描述

我想在运行 test.php 时下载 wordpress_db1.sql 文件,但我总是在它上面空着。我怎样才能解决这个问题?谢谢!

4

2 回答 2

6

下面的代码将为您解决问题。

<?php 
$file_name = 'file.sql';
$file_url = 'http://www.example.com/' . $file_name;
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"".$file_name."\""); 
readfile($file_url);
?>

你做错了什么readfile($file_url);。设置标题不会完成工作。你有用 readfile($file_url);

于 2013-02-07T04:44:47.550 回答
5

设置标题不会读取文件。您可以在附件中将文件命名为任何您想要的名称。您必须实际发出文件:

readfile('wordpress_db1.sql');
于 2013-02-07T04:42:14.750 回答