0

我必须创建一个文本文件并使其可下载,而无需在单击按钮时保存到我的目录中。下面我提到了生成文件的文件代码。

<?php
    $data = "ffff dfjdhjf  jhfjhf f f hlm hoejrherueirybgb,nvbd;ihrtmrn.";
    $filename = "SU_Project_Startup.txt";
    $fh = fopen($filename, "w+");
    fwrite($fh, $data, strlen($data));
    fclose($fh);

    header('Content-type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    ob_end_flush();
    echo $data;
    exit();
?>

你能告诉我在这段代码中我还需要做哪些更改吗?

提前致谢

4

2 回答 2

1

试试这个标题:

header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/json"); // here is your type
header("Content-Transfer-Encoding: binary");
于 2012-10-20T08:07:52.380 回答
0

这是url拍照的例子

你可以试一试,或者把它投入使用

 <?php
    header('Content-type: application/octet-stream');
    header('Content-Disposition: attachment; filename="File-name.jpg"');
    $fileurl = 'http://upload.wikimedia.org/wikipedia/commons/thumb/c/cc/Ramses_II_at_Kadesh.jpg/120px-Ramses_II_at_Kadesh.jpg';
    $data =  file_get_contents($fileurl);
    echo $data;
?>
于 2012-10-20T08:12:57.317 回答