ホームページ > php教程 > php手册 > PHP は Header() 関数を介してファイルのダウンロードを実装します

PHP は Header() 関数を介してファイルのダウンロードを実装します

WBOY
リリース: 2016-06-21 08:52:34
オリジナル
827 人が閲覧しました

PHP は、次のコードに示すように、Header() 関数を介してファイルのダウンロードを実装します。

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span class="tag-name">html</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"><</span><span class="tag-name">head</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"><</span><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"Content-Type"</span><span> </span><span class="attribute">content</span><span>=</span><span class="attribute-value">"text/html; charset=gb2312"</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"><</span><span class="tag-name">title</span><span class="tag">></span><span>应用header()函数实现下载 - www.cxybl.com</span><span class="tag"></</span><span class="tag-name">title</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"><</span><span class="tag-name">style</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/css"</span><span class="tag">></span><span> </span></span></li>
<li>
<span><!-- </span></li><li class="alt"><span>body { </span></li><li><span>    margin-left: 00px; </span></li><li class="alt"><span>    margin-top: 0px; </span></li><li><span>    margin-right: 0px; </span></li><li class="alt"><span>    margin-bottom: 0px; </span></li><li><span>} </span></li><li class="alt"><span>a:link { </span></li><li><span>    text-decoration: none; </span></li><li class="alt"><span>} </span></li><li><span>a:visited { </span></li><li class="alt"><span>    text-decoration: none; </span></li><li><span>} </span></li><li class="alt"><span>a:hover { </span></li><li><span>    text-decoration: none; </span></li><li class="alt"><span>} </span></li><li><span>a:active { </span></li><li class="alt"><span>    text-decoration: none; </span></li><li><span>} </span></li><li class="alt"><span>.style1 {font-size: 12px} </span></li><li><span>--<span class="tag">></span><span> </span>
</li>
<li class="alt"><span><span class="tag"></</span><span class="tag-name">style</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">head</span><span class="tag">></span><span> </span></span></li>
<li><span> </span></li>
<li class="alt"><span><span class="tag"><</span><span class="tag-name">body</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"><</span><span class="tag-name">table</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"385"</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"185"</span><span> </span><span class="attribute">border</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">cellpadding</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">cellspacing</span><span>=</span><span class="attribute-value">"0"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>    <span class="tag"><</span><span class="tag-name">form</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"form1"</span><span> </span><span class="attribute">method</span><span>=</span><span class="attribute-value">"post"</span><span> </span><span class="attribute">action</span><span>=</span><span class="attribute-value">"index_ok.php"</span><span class="tag">></span><span> </span></span></li>
<li><span>  <span class="tag"><</span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>    <span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"55"</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"85"</span><span class="tag">></span><span> </span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li><span>    <span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"275"</span><span class="tag">></span><span> </span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>    <span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"55"</span><span class="tag">></span><span> </span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li><span>  <span class="tag"></</span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>  <span class="tag"><</span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li><span>    <span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"30"</span><span class="tag">></span><span> </span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>    <span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"submit"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"Submit"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"同意"</span><span class="tag">></span><span> </span></span></li>
<li><span>        <span class="tag"><</span><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"reset"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"Submit2"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"不同意"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>    <span class="tag"><</span><span class="tag-name">td</span><span class="tag">></span><span> </span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li><span>  <span class="tag"></</span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>  <span class="tag"><</span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li><span>    <span class="tag"><</span><span class="tag-name">td</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"30"</span><span class="tag">></span><span> </span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>    <span class="tag"><</span><span class="tag-name">td</span><span class="tag">></span><span> </span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li><span>    <span class="tag"><</span><span class="tag-name">td</span><span class="tag">></span><span> </span><span class="tag"></</span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>  <span class="tag"></</span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li><span>   <span class="tag"></</span><span class="tag-name">form</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"></</span><span class="tag-name">table</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"></</span><span class="tag-name">body</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"></</span><span class="tag-name">html</span><span class="tag">></span><span> </span></span></li>
</ol>
ログイン後にコピー
index_ok.php:

<ol class="dp-c"><li class="alt"><span><span><?php session_start(); </span></span></li><li><span>       <span class="keyword">if</span><span>(</span><span class="vars">$Submit</span><span>==</span><span class="string">"同意"</span><span>){ </span></span></li><li class="alt"><span>       header(<span class="string">"location:http://www.cxybl.com/templets/default/images/logo1.gif"</span><span>);} </span></span></li><li><span>?> </span></span></li></ol>
ログイン後にコピー



関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のおすすめ
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート