<?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; code</title>
	<atom:link href="http://naeh.net/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://naeh.net</link>
	<description>Le mémo du développeur</description>
	<lastBuildDate>Wed, 30 Jun 2010 18:56:54 +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>
		<item>
		<title>PHP 5, un constructeur et un destructeur uniformisés</title>
		<link>http://naeh.net/php-5-un-constructeur-et-un-destructeur-uniformises/</link>
		<comments>http://naeh.net/php-5-un-constructeur-et-un-destructeur-uniformises/#comments</comments>
		<pubDate>Sun, 04 Feb 2007 21:46:16 +0000</pubDate>
		<dc:creator>Naeh</dc:creator>
				<category><![CDATA[PHP / MySQL]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[constructeur]]></category>
		<category><![CDATA[destructeur]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://wp.naeh.info/?p=14</guid>
		<description><![CDATA[Avec PHP 5, les choses deviennent plus simples et plus logiques: toute méthode réservée par PHP 5 est préfixée par __ (double soulignement ou underscore). C'est le cas notamment du constructeur déclaré par la méthode __construct et du destructeur déclaré par __destruct. Il faut noter malheureusement, qu'il n'est toujours pas possible de déclarer plusieurs constructeurs [...]]]></description>
			<content:encoded><![CDATA[<p>Avec PHP 5, les choses deviennent plus simples et plus logiques: toute méthode réservée par PHP 5 est préfixée par __ (double soulignement ou underscore). C'est le cas notamment du constructeur déclaré par la méthode __construct et du destructeur déclaré par __destruct. Il faut noter malheureusement, qu'il n'est toujours pas possible de déclarer plusieurs constructeurs avec des paramètres différents alors qu'il est maintenant possible de typer les paramètres de méthode.</p>
<p>Voici un exemple d'utilisation de constructeur et de destructeur:</p>

<div class="wp_codebox"><table><tr id="p146"><td class="code" id="p14code6"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// La ligne ci-dessous permet d'afficher tout texte comme texte simple et non comme</span>
<span style="color: #666666; font-style: italic;">// du HTML. C'est utile si nous utiliserons la fonction print_r/print('n')</span>
<span style="color: #666666; font-style: italic;">// (voir la documentation PHP pour plus d'info)</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/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Utilisateur <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$nom</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$prenom</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$dateNaissance</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> Utilisateur<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nom</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prenom</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dateNaissance</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Utilisateur(<span style="color: #006699; font-weight: bold;">$nom</span>, <span style="color: #006699; font-weight: bold;">$prenom</span>, <span style="color: #006699; font-weight: bold;">$dateNaissance</span>=null) appelé&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nom</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prenom</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dateNaissance</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;__construct(<span style="color: #006699; font-weight: bold;">$nom</span>, <span style="color: #006699; font-weight: bold;">$prenom</span>, <span style="color: #006699; font-weight: bold;">$dateNaissance</span>=null) appelé&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>nom <span style="color: #339933;">=</span> <span style="color: #000088;">$nom</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>prenom <span style="color: #339933;">=</span> <span style="color: #000088;">$prenom</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>dateNaissance <span style="color: #339933;">=</span> <span style="color: #000088;">$dateNaissance</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;__destruct() appelé&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>nom<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>prenom<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>dateNaissance<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$utilisateur</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Utilisateur<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MARTIN&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Pierre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$utilisateur</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Vous remarquerez à l'exécution que l'ancien constructeur PHP 4 n'est plus utilisé. C'est totalement normal dès que vous utilisez un constructeur de type PHP 5. Ceci permet une compatibilité ascendante de PHP et ainsi de pouvoir continuer d'utiliser des classes développées pour PHP 4 avec la dernière version du langage.</p>
<p>L'appel du destructeur est fait implicitement par le moteur de PHP à la fin du script. Mais si vous souhaitez faire de la programmation propre, vous devez l'appeler explicitement avec le mot clé <strong>unset</strong> qui existe déjà avec PHP 4. C'est ce que nous faisons avec le unset($utilisateur) à la fin du code. Nous le faisons aussi dans le destructeur de la classe Utilisateur.</p>
<p>Si nous avions utilisé des objets pour stocker les attributs de cette classe (des objets String par exemple), leurs destructeurs respectifs auraient, eux aussi, été appelés produisant un effet "domino" sur l'ensemble des objets utilisés.</p>
<p>Pour les connaisseurs, l'équivalent du mot clé unset en langage C++ est delete (un temps envisagé semble-t-il avec PHP 5).</p>
<p>Source : <a href="http://www.toutprogrammer.com/" target="_blank">http://www.toutprogrammer.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://naeh.net/php-5-un-constructeur-et-un-destructeur-uniformises/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
