1

So far here what i've tried it can download the sql file but it is empty

//test.php

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

Here is what my root folder look like

enter image description here

I want to download the wordpress_db1.sql file when I run the test.php but I always get empty on it. How can I fix this? thanks!

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 に答える