PHP で隠しパスのダウンロードを実装する方法: 1. "download_document" メソッドを通じて実際のファイルのダウンロード アドレスを非表示にします; 2. "if (file_exists($file)) {. ..}" メソッドのアドレス。

#この記事の動作環境: Windows7 システム、PHP7.1 バージョン、DELL G3 コンピューター
php で非表示にするメソッド実際のファイルのダウンロード アドレス
この記事では、PHP で実際のファイルのダウンロード アドレスを非表示にする方法を主に紹介しており、PHP の header メソッドと file_get_contents メソッドの関連使用スキルも含まれており、非常に実用的です。困っている友人は以下を参照してください:
実装方法 1:
1 2 3 4 5 6 7 8 | function download_document( $filename , $path = "" , $mimetype = "application/octet-stream" )
{
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Content-Disposition: attachment; filename = $filename" );
header( "Content-Length: " . filesize ( $pathto . $filename ));
header( "Content-Type: $mimetype" );
echo file_get_contents ( $pathto . $filename );
}
|
ログイン後にコピー
実装方法 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php
$file = "1.txt" ;
if ( file_exists ( $file )) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='. basename ( $file ));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public ');
header('Content-Length: ' . filesize ( $file ));
ob_clean();
flush ();
readfile( $file );
exit ;
}
?>
|
ログイン後にコピー
[推奨学習:
PHP ビデオ チュートリアル ]
以上がPHPでダウンロードパスを非表示にする方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。