0

テキスト ファイルを 1 つ作成し、ボタンのクリック時にディレクトリに保存せずにダウンロードできるようにする必要があります。以下に、ファイルを生成するファイルのコードについて説明しました。

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