2

含まれているボタンをクリックすると、ダウンロード ダイアログを開いて特定のファイルをダウンロードするフォームを作成しました。ファイルは同じサーバーに配置されます。

私は試した:

header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=" . $file . '"'); 

$file はローカル パス + ファイル名です (例: c:\mypath\myfile.xls)。ただし、これは機能しません。ファイルが提供されますが、有効なファイルではありません。他にどうすればそれができますか?

注: c:\ と書いたのは、まだテスト用にローカル マシンにあるためです。

ありがとう!

4

4 に答える 4

3

これを試して

header("Pragma: public", true);
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($file));
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
die(file_get_contents($file));

file_get_contents() 関数は PHP 5.0.3 では動作しなくなったと思います

于 2013-03-01T11:36:28.830 に答える
1

これを試して :

$path = "http://www.example.com/files/";
$filename = "abc.gif";

header("Content-Type:image/gif");
header("Content-Disposition: attachment; filename=".$filename);
header("キャッシュ制御: プライベート");
header('X-Sendfile: '.$path);
readfile($パス);
出口;
于 2013-03-01T11:37:12.147 に答える
0

PHP はサーバー側で実行されるため、クライアント マシンにファイルをダウンロードすることはできません。

ファイルをサーバーにアップロードし、そのパスをダウンロード用に指定します。

于 2013-03-01T11:34:04.203 に答える
0

パスはサイトのルートから参照する必要があります...ファイルを移動 ex: script path : C:/wamp/www/test.php file C:/script.js 次に:

if(file_exists('../../user.js'))
{
    echo "OK";
}

まだ悪い考え..

于 2013-03-01T11:34:07.353 に答える