<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Naeh.net &#187; telecharger</title>
	<atom:link href="http://naeh.net/tag/telecharger/feed/" rel="self" type="application/rss+xml" />
	<link>http://naeh.net</link>
	<description>Le mémo du développeur</description>
	<lastBuildDate>Thu, 09 Sep 2010 15:30:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Forcer le téléchargement d&#8217;un fichier avec PHP</title>
		<link>http://naeh.net/forcer-le-telechargement-dun-fichier-avec-php/</link>
		<comments>http://naeh.net/forcer-le-telechargement-dun-fichier-avec-php/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 22:16:33 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Serveur]]></category>
		<category><![CDATA[telecharger]]></category>

		<guid isPermaLink="false">http://naeh.net/forcer-le-telechargement-dun-fichier-avec-php/</guid>
		<description><![CDATA[Dance cet article nous allons voir comment forcer le navigateur à télécharger un fichier (n'importe lequel) au lieux de l'ouvrir. Pour cela nous allons utiliser les Headers qu'envoie le serveur au navigateur (fonction header de php).
Voici le code a utiliser :

 //date actuelle
$date = gmdate&#40;'D, d M Y H:i:s'&#41;;
&#160;
header&#40;&#34;Content-Type: text/xml&#34;&#41;; //Ici par exemple c'est pour [...]]]></description>
			<content:encoded><![CDATA[<p>Dance cet article nous allons voir comment forcer le navigateur à télécharger un fichier (n'importe lequel) au lieux de l'ouvrir. Pour cela nous allons utiliser les <strong>Headers</strong> qu'envoie le serveur au navigateur (<a href="http://fr3.php.net/manual/fr/function.header.php" target="_blank">fonction header de php</a>).</p>
<p>Voici le code a utiliser :</p>

<div class="wp_codebox"><table><tr id="p503"><td class="code" id="p50code3"><pre class="php" style="font-family:monospace;"> <span style="color: #666666; font-style: italic;">//date actuelle</span>
<span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/gmdate"><span style="color: #990000;">gmdate</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Ici par exemple c'est pour un fichier XML, a changer en fonction du type mime du fichier voulu.</span>
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=NOM_FICHIER.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Last-Modified: '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$date</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' GMT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Expires: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//header specifique IE :s parce que sinon il aime pas</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/msie|(microsoft internet explorer)/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cache-Control: must-revalidate, post-check=0, pre-check=0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pragma: public'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
  <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pragma: no-cache'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$CONTENU_DE_NOTRE_FICHIER</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ou readfile('CHEMIN_FICHIER'); En fonction du type de fichier.</span></pre></td></tr></table></div>

<p>Le type Mime doit être celui du fichier qu'on veut pouvoir télécharger (<a href="http://www.c-p-f.org/divers-Liste_des_types_MIME-a15.html" target="_blank">liste des types mime disponibles</a>). En voici quelques exemples :</p>

<div class="wp_codebox"><table><tr id="p504"><td class="code" id="p50code4"><pre class="bash" style="font-family:monospace;">image GIF : image<span style="color: #000000; font-weight: bold;">/</span>gif
fichier XML : text<span style="color: #000000; font-weight: bold;">/</span>xml
fichier rtf : application<span style="color: #000000; font-weight: bold;">/</span>rtf
fichier avi : video<span style="color: #000000; font-weight: bold;">/</span>msvideo</pre></td></tr></table></div>

<p>Maintenant à vos fichiers dl.php ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://naeh.net/forcer-le-telechargement-dun-fichier-avec-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
