ホームページ  >  記事  >  バックエンド開発  >  php_PHP チュートリアルでファイルをダウンロードするコード例

php_PHP チュートリアルでファイルをダウンロードするコード例

WBOY
WBOYオリジナル
2016-07-21 15:18:35710ブラウズ

コードをコピーします コードは次のとおりです:

$file = 'monkey.gif';

if (file_exists($file)) {
header('Content-Description: File転送') ;
header('Content-Type: application/octet-stream');
header('Content-Disposition:attachment; filename='.basename($file)); : バイナリ' );
header('有効期限: 0');
header('キャッシュ制御: 再検証が必要、事前チェック=0'); ;
header ('Content-Length: ' . filesize($file));
readfile($file);


;はダウンロード コードです
​​ 次に、PDF ファイルのオンライン プレビュー用のコードを投稿します



コードをコピーします

コードは次のとおりです:

public function fddAction() { // get添付ファイルの場所 $attachment_location = $_SERVER[" DOCUMENT_ROOT"] . "/pdf/fdd/sample.pdf";
if (file_exists($attachment_location)) {
// 添付ファイルが存在します

// 開く PDF ダイアログを送信しますuser
header('Cache-Control: public '); // 例:
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="sample.pdf"') );
readfile($attachment_location);
die(); // pdf を出力するだけなので、以降のスクリプトの実行を停止します

} else {
die('エラー: ファイルが見つかりません。');
?>





http://www.bkjia.com/PHPjc/325507.html

www.bkjia.com

tru​​e
http://www.bkjia.com/PHPjc/325507.html

技術記事次のようにコードをコピーします。 ?php $file = 'monkey.gif'; if (file_exists($file)) { header('Content-Description: File Transfer'); '); 頭...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。