<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://www.code-web.org/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>Code-Web.org - html</title>
  <link>http://www.code-web.org/</link>
  <description>Développement Web en toute liberté!</description>
  <language>fr</language>
  <pubDate>Mon, 08 Sep 2008 10:48:53 +0200</pubDate>
  <copyright></copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Des formulaires accessibles</title>
    <link>http://www.code-web.org/post/2008/03/11/47-des-formulaires-accessibles</link>
    <guid isPermaLink="false">urn:md5:e464a1b824dfc3b9f275c55cce28045f</guid>
    <pubDate>Tue, 11 Mar 2008 16:54:00 +0000</pubDate>
    <dc:creator>Thierry Geindre</dc:creator>
        <category>Html / CSS</category>
        <category>accessibilité</category><category>html</category>    
    <description>&lt;p&gt;Votre site passe au validateur du W3C? Parfait vous avez respecté une norme à la lettre en développant votre site et on ne peut que vous en féliciter. Pourquoi ne pas jeter un petit coup d'œil à vos formulaires en vous appuyant sur les quelques conseils que je vous donne dans cet article. Vous y trouverez quelques petites astuces pour rendre les formulaires plus accessibles et pratiques à utiliser. On y fera également un petit point sur l'emploi de javascript pour la validation ceux-ci.&lt;/p&gt;    &lt;h3&gt;Les balise oubliées du web&lt;/h3&gt;

&lt;p&gt;Titre étrange me direz-vous, mais admettons que beaucoup de sites se privent de l'emploi des balises que nous allons voir. Et pour cause, elles ne sont absolument pas indispensables au bon fonctionnement d'un formulaire. Cependant, leur emploi pourra faciliter l'utilisation de vos formulaires par vos visiteurs, alors utilisez-les!&lt;/p&gt;


&lt;h4&gt;Label&lt;/h4&gt;

&lt;p&gt;Tout champ d'un formulaire dispose de son propre label. Ils ne sont cependant que rarement identifiés comme tel dans le code HTML. Pour ce faire, on utilise simplement la balise &amp;lt;label&amp;gt; pour encadrer label d'un champ. Voyons un petit exemple&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Nom : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;nom&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Vous remarquerez dans cet exemple que la balise &amp;lt;label&amp;gt; englobe le champ et son label. Cela sous entend que ce label et ce champ son associés. Cependant, certaines mise en page ne permettront pas de les associer sur la même ligne de code. Pour remédier à cela, il est possible d'attribuer au champ concerné un &lt;em&gt;id&lt;/em&gt; et de l'indiquer dans l'attribut &lt;em&gt;for&lt;/em&gt; de la balise &amp;lt;label&amp;gt;. On procédera alors ainsi&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;nom&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Nom&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;nom&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;nom&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;L'emploi de cette balise entraînera, pour le navigateur, une association entre le champ et son label. Ainsi le fait de cliquer sur le texte correspondant au champ placera automatique le focus sur le champ concerné.&lt;/p&gt;


&lt;h4&gt;Fieldset&lt;/h4&gt;

&lt;p&gt;Grouper les champs d'un formulaire lorsque cela est utile et faisable est un plus non négligeable pour un formulaire. Pour cela nous disposons de deux balises&amp;nbsp;: &amp;lt;fieldset&amp;gt; et &amp;lt;legend&amp;gt;. La première permet d'englober différents champs de votre formulaire portant sur le même type de données. La seconde permet de donner une légende à ce groupe de champs. Elles s'utilisent ainsi&amp;nbsp;:&lt;/p&gt;


&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;&lt;/span&gt;Nom&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Nom : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;nom&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Pr&lt;span style=&quot;color: #ddbb00;&quot;&gt;&amp;amp;eacute;&lt;/span&gt;nom : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;prenom&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;&lt;/span&gt;Adresse&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Addresse : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;textarea&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;addresse&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/textarea&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Code postal : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;postcode&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;&lt;/span&gt;
...&lt;/pre&gt;


&lt;p&gt;Vous pouvez voir, dans cet exemple, de quelle manière nous pouvons grouper les différents champs d'un formulaire. Attention tout de même  ne pas grouper à outrance et à n'employer ceci que lorsque que c'est nécessaire. Il ne s'agit pas ici de travailler la mise en forme.&lt;/p&gt;


&lt;h4&gt;Groupes d'options, optgroup&lt;/h4&gt;

&lt;p&gt;Il s'agit ici de grouper les options d'une liste par catégories. Ceci évitera, par exemple, l'emploi de &lt;em&gt;fausses options&lt;/em&gt; comme on peut le voir sur certains sites. Pour cela, il existe la balise &amp;lt;optgroup&amp;gt; qui doit être utiliser directement dans la liste des options d'une liste. Elle dispose d'un attribut label qui permet de définir quel texte sera afficher pour le groupe d'options.&lt;/p&gt;

&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;select&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;pays&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;optgroup&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Europe&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;option&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;France&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;option&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;uk&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Royaule Uni&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/optgroup&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;optgroup&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Am&amp;amp;eacute;rique&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;option&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;us&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;USA&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;option&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;ca&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Canada&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/optgroup&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Ceci produira, pour chaque &amp;lt;optgroup&amp;gt; une ligne dans la liste des options non sélectionnable et qui disposera d'une mise en forme particulière qui l'identifiera clairement comme une entête de catégorie.&lt;/p&gt;


&lt;h4&gt;Tabindex&lt;/h4&gt;

&lt;p&gt;Tabindex est un attribut de champs de formulaire. Il sert à définir dans quel ordre les champs devront être parcourut lorsque votre visiteur utilise la touche tab pour naviguer d'un champ à l'autre. Cet attribut se révélera particulièrement utile lorsque les champs n'apparaissent pas dans le même ordre dans le code html de la page et à l'affichage.&lt;/p&gt;


&lt;p&gt;Il s'utilise très simplement de la façon suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;&lt;/span&gt;Nom&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Nom : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;tabindex&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;nom&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Pr&lt;span style=&quot;color: #ddbb00;&quot;&gt;&amp;amp;eacute;&lt;/span&gt;nom : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;tabindex&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;2&amp;quot;&lt;/span&gt;  &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;prenom&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;&lt;/span&gt;Adresse&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Addresse : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;textarea&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;addresse&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;tabindex&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;3&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/textarea&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Code postal : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;tabindex&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;4&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;postcode&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;Pays : &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;select&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;pays&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;tabindex&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;5&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;optgroup&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Europe&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;option&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;France&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;option&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;uk&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Royaule Uni&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/optgroup&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;optgroup&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Am&amp;amp;eacute;rique&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;option&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;us&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;USA&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;option&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;ca&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Canada&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/optgroup&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;A propos d'accesskey&lt;/h4&gt;

&lt;p&gt;Accesskey est également un attribut de champ. Il permet de définir, comme son nom l'indique, une touche d'accès. Comprenez un raccourci clavier. Cependant il est préférable de ne pas l'employer sur un site web. Il pourra éventuellement être utilisé pour une application Intranet. Voyez &lt;a href=&quot;http://blog.alsacreations.com/2005/09/27/191-accesskey-le-grand-echec-de-laccessibilite-du-web&quot; hreflang=&quot;fr&quot;&gt;l'article d'Alsacreations&lt;/a&gt; pour en savoir plus à ce propos.&lt;/p&gt;


&lt;h3&gt;La validation d'un formulaire avec du Java Script&lt;/h3&gt;


&lt;p&gt;Ici je m'attaque à un problème récurent, réel et qui provoque chez moi un énervement destructeur pour la touche &lt;em&gt;return&lt;/em&gt; de mon clavier! Alors &lt;strong&gt;je lance ici un appel à tous les développeurs&lt;/strong&gt;, même &lt;strong&gt;amateurs et improvisés&lt;/strong&gt;, pour le respect de quelques simples règles d'accessibilité dans le développement et le contrôle de saisies d'un formulaire via Java Script.&lt;/p&gt;


&lt;p&gt;Après ces quelques mots, entrons maintenant dans le vif du sujet. Beaucoup de formulaires emploient du Java Script pour le contrôle des saisies de l'utilisateur. Ceci apporte son petit lots d'avantages&amp;nbsp;: Évite à l'utilisateur d'attendre un rechargement de la page pour la vérification des données et diminue la bande passante utilisée par le site ou l'application (plutôt à long terme). Malheureusement, la manière dont est employé le code de vérification est souvent gênante (voir bloquante) pour certains utilisateurs.&lt;/p&gt;


&lt;p&gt;Je ne vais pas m'étaler ici sur plusieur lignes supplèmentaire d'explication et je vais m'en remettre à un article d'OpenWeb. J'ai déjà donné ce lien dans un précédent post, mais il me parait tellement important que je le redonne ici&amp;nbsp;: &lt;a href=&quot;http://openweb.eu.org/articles/validation_formulaire/&quot; hreflang=&quot;fr&quot;&gt;Validation des formulaires avec Java Script&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.code-web.org/post/2008/03/11/47-des-formulaires-accessibles#comment-form</comments>
      <wfw:comment>http://www.code-web.org/post/2008/03/11/47-des-formulaires-accessibles#comment-form</wfw:comment>
      <wfw:commentRss>http://www.code-web.org/feed/rss2/comments/32</wfw:commentRss>
    						<h3>Abonnement aux commentaires</h3>
						<p>
							<a href="http://www.code-web.org/subscribetocomments?post_id=32">
								<!-- # If the subscriber is logged in -->
																<!-- # If the subscriber is not logged in -->
																	S'abonner pour recevoir les commentaires suivants par email															</a>
						</p>
					  </item>
    
  <item>
    <title>Un arrière plan étirable</title>
    <link>http://www.code-web.org/post/2008/02/15/46-un-arriere-plan-etirable</link>
    <guid isPermaLink="false">urn:md5:e08ac15a9942168906ef3e4c52c74dcc</guid>
    <pubDate>Fri, 15 Feb 2008 22:32:00 +0000</pubDate>
    <dc:creator>Thierry Geindre</dc:creator>
        <category>Html / CSS</category>
        <category>design</category><category>html</category>    
    <description>&lt;p&gt;Les propriétés CSS permettant d'appliquer une image d'arrière plan aux éléments d'une page, ou à la page elle même, ne permettent de couvrir toute la surface disponible que par répétition de l'image. Je vous propose ici une méthode permettant détirer l'image en hauteur et/ou en largeur en fonction de l'espace disponible. A noter qu'à l'inverse de beaucoup de solutions proposées sur la toile, celle que je vous propose n'utilise pas de java script.&lt;/p&gt;    &lt;h3&gt;Le principe&lt;/h3&gt;


&lt;p&gt;Les propriétés CSS ne satisfaisant pas nos exigences, nous allons devoir utiliser une autre technique. Pour cela, nous utiliserons une classique image (balise &amp;lt;img ... /&amp;gt;). La méthode consistera en fait à lui donner des dimensions à 100%. Elle s'étirera donc automatiquement en fonction des éventuels changements de dimensions.&lt;/p&gt;


&lt;p&gt;Puisqu'il s'agit d'un arrière plan, nous allons devoir placer du contenu par dessus. Pour cela, nous allons devoir modifier le mode de positionnement de ce contenu en fonction du contexte.&lt;/p&gt;


&lt;h3&gt;L'arrière plan d'une page&lt;/h3&gt;

&lt;p&gt;Pour cela nous allons d'abord supprimer les éventuelles marges du corps de la page. Nous lui donnerons également des dimensions à 100% sans quoi cette astuce ne fonctionnera pas sous certaines versions d'Internet Explorer.&lt;/p&gt;


&lt;p&gt;Nous placerons ensuite note image de fond dans la première ligne de contenu de l'élément &amp;lt;body&amp;gt;. Les dimensions de cette images seront définies à 100%.&lt;/p&gt;


&lt;p&gt;Enfin, pour que le contenu se place par dessus cette image, on pourra le placer dans un élément de type &amp;lt;div&amp;gt; (ou tout autre conteneur) que nous positionnerons en absolute.&lt;/p&gt;

&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #00bbdd;&quot;&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Strict//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;html&lt;/span&gt; xmlns&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/span&gt; xml:&lt;span style=&quot;color: #000066;&quot;&gt;lang&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;lang&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;&lt;/span&gt;Un exemple&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;meta&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;http-equiv&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Content-Type&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text/html; charset=iso-8859-1&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;style&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&amp;nbsp;
   body,html
   {
     /* Indispensables pour certain navigateurs */
     width:100%;
     height:100%;
     /* On retire les marges éventuelles */
     margin:0;
     padding:0;
    }
&amp;nbsp;
    #background
    {
     width:100%;
     height:100%;
    }
&amp;nbsp;
    #content
    {
     position:absolute;
     left:0;
     top:0;
    }
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;src&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;images/background.png&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;alt&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;background&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;content&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
     &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;Le contenu de la page se place dans ce div!&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Vous pouvez vérifier le bon fonctionnement de cette astuce grâce à &lt;a href=&quot;http://exemples.code-web.org/arriere-plan-etirable/&quot; hreflang=&quot;fr&quot;&gt;l'aperçu&lt;/a&gt; que je vous propose. Redimensionnez la fenêtre et observez l'image prendre les bonnes dimensions. Vous remarquerez en passant que les proportions de l'image ne sont pas forcément respectées. Si vous souhaitez conserver les bonnes proportions, il vous suffira de ne préciser la dimension 100% que pour la hauteur ou la largeur de l'image.&lt;/p&gt;


&lt;p&gt;Vous remarquerez peut être que cette page n'est pas valide. En effet, une balise &amp;lt;img ... /&amp;gt; ne peut normalement pas apparaître dans ce contexte, il faudrait logiquement qu'elle soit placé entre des éléments &amp;lt;h1&amp;gt; ou &amp;lt;p&amp;gt; par exemple. Cependant, en plus d'être impossible à justifier à cette endroit, l'utilisation de ces balises ne permet pas d'obtenir le comportement attendu sur certain navigateurs.&lt;/p&gt;


&lt;p&gt;Remarquez enfin que nous avons laissé le texte alternatif de l'image vide. Ceci s'explique simplement&amp;nbsp;: aucun texte alternatif n'aurait de sens à cette endroit. De plus, si pour une raison ou une autre il apparaissait, il pourrait nuire à la bonne lecture de la page par le visiteur (superposition de texte).&lt;/p&gt;


&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Il est probablement préférable d'utiliser cette astuce avec modération. Je n'ai pas eu l'occasion de la tester sur beaucoup de navigateurs. &lt;a href=&quot;http://www.alsacreations.com/&quot; hreflang=&quot;fr&quot;&gt;Alsacreations&lt;/a&gt; nous indique que cette technique fonctionne sur les navigateurs suivant&amp;nbsp;: &lt;em&gt;sur Windows IE5, IE5.5, IE6, Mozilla Firebird 0.7, Mozilla Firefox 0.8 et Opera 7.23&lt;/em&gt;. Pour ma part, j'ai pu vérifier avec les versions Linux de Firefox 2.0 et Opera.&lt;/p&gt;



&lt;p&gt;Vous pourrez également appliquer cette méthode à d'autre éléments de votre page. La technique restant rigoureusement la même.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.code-web.org/post/2008/02/15/46-un-arriere-plan-etirable#comment-form</comments>
      <wfw:comment>http://www.code-web.org/post/2008/02/15/46-un-arriere-plan-etirable#comment-form</wfw:comment>
      <wfw:commentRss>http://www.code-web.org/feed/rss2/comments/31</wfw:commentRss>
    						<h3>Abonnement aux commentaires</h3>
						<p>
							<a href="http://www.code-web.org/subscribetocomments?post_id=31">
								<!-- # If the subscriber is logged in -->
																<!-- # If the subscriber is not logged in -->
																	S'abonner pour recevoir les commentaires suivants par email															</a>
						</p>
					  </item>
    
  <item>
    <title>Upload de fichiers via formulaire avec PHP</title>
    <link>http://www.code-web.org/post/2008/01/14/40-upload-de-fichiers-via-formulaire-avec-php</link>
    <guid isPermaLink="false">urn:md5:970fdd726cba736a6e375f6b37f5dc06</guid>
    <pubDate>Mon, 14 Jan 2008 16:10:00 +0000</pubDate>
    <dc:creator>Thierry Geindre</dc:creator>
        <category>PHP</category>
        <category>apache</category><category>automatisation</category><category>html</category><category>php</category>    
    <description>&lt;p&gt;L'utilisation d'un langage côté serveur permet d'automatiser ou de simplifier bon nombre de tâches d'administration. L'upload (envoi) de fichiers fait partie de ces tâches qui peuvent être simplifiées. En effet, il est possible d'envoyer vos fichiers via un formulaire sur une page web puis d'effectuer le traitement de celui-ci grâce à PHP. Il ne sera donc plus nécessaire d'utiliser à chaque fois un client FTP.&lt;/p&gt;


&lt;p&gt;Ceci pourra être très pratique dans le cas de l'administration d'une galerie photo par exemple, ou encore simplement pour illustrer vos publications.&lt;/p&gt;    &lt;h3&gt;Pré requis&lt;/h3&gt;

&lt;h4&gt;Droits d'écriture&lt;/h4&gt;

&lt;p&gt;Pour que l'upload de fichiers puisse fonctionner correctement, il est impératif que le répertoire dans lequel on souhaitera placer les fichiers soit accessible en écriture. Sur certains systèmes, les dossiers sont toujours accessibles en écriture, c'est le cas de Windows (&amp;lt; Vista). En revanche, sur d'autres, tel que les systèmes dérivés d'UNIX, il est possible d'interdire l'écriture dans certains répertoires.&lt;/p&gt;


&lt;p&gt;Ce réglage ne sera donc nécessaire que si le système de la machine qui héberge votre site utilise un mécanisme de gestions de droits sur les fichiers et répertoires.&lt;/p&gt;


&lt;p&gt;Pour autoriser l'écriture, vous avez plusieurs possibilités. Soit en utilisant votre client FTP, auquel cas vous pourrez modifier les droits en accédant aux attributs ou aux propriétés de votre répertoire. Vous pouvez également modifier les droits de votre répertoire grâce à la fonction &lt;a href=&quot;http://fr.php.net/chmod&quot; hreflang=&quot;fr&quot;&gt;chmod()&lt;/a&gt; de PHP (reportez-vous à la documentation). Enfin, si vous avez accès directement au système de la machine (par SSH par exemple), vous pourrez modifier les droits très facilement grâce aux commandes appropriées (reportez vous à la documentation de votre système).&lt;/p&gt;


&lt;h4&gt;Configuration de php (php.ini)&lt;/h4&gt;

&lt;p&gt;Pour que l'envoie de fichiers fonctionne, PHP doit être configuré de la bonne manière. Ainsi certaine directives doivent avoir certaines valeurs. Vous pouvez modifier ces valeurs dans le fichier php.ini ou grâce à la fonction &lt;a href=&quot;http://fr.php.net/ini_set&quot; hreflang=&quot;fr&quot;&gt;ini_set()&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;file_uploads&lt;/strong&gt; est la directive qui autorise ou interdit l'upload de fichier. Sa valeur doit donc être &lt;em&gt;on&lt;/em&gt; (inverse de off).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;upload_tmp_dir&lt;/strong&gt; correspond au répertoire dans lequel seront placé les fichiers temporairement uploadés. Ce répertoire doit lui aussi être accessible en écriture. Sur les systèmes UNIX et dérivés il s'agira souvent du répertoire /tmp/ accessible en écriture pour tous les utilisateurs du système.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;upload_max_filesize&lt;/strong&gt; détermine la taille maximal de l'envoi d'un fichier. Il n'y a pas de valeur parfaite mais &lt;em&gt;2M&lt;/em&gt; est une valeur courante et satisfaisante dans la plupart des cas. Elle correspond à 2 méga octets.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;post_max_size&lt;/strong&gt; correspond au volume maximum d'informations qui peuvent être envoyées via la méthode POST. Cette directive prime sur la précédente et doit logiquement avoir une valeur au moins égale. C'est pourquoi, là encore, &lt;em&gt;2M&lt;/em&gt; est une valeur satisfaisante.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Si vous rencontrez des difficultés dans l'upload de vos fichiers avec la méthodes que nous allons voir, c'est probablement à cause de votre configuration. SI vous ne pouvez pas y avoir accès (cas des hébergement mutualisés), utilisez la fonction &lt;a href=&quot;http://fr.php.net/phpinfo&quot; hreflang=&quot;fr&quot;&gt;phpinfo()&lt;/a&gt; qui vous donnera toutes les informations de configuration de php.&lt;/p&gt;


&lt;h3&gt;Le formulaire HTML&lt;/h3&gt;

&lt;p&gt;La première étape est de créer notre formulaire en HTML qui permettra l'envoie de fichiers au serveur. Pour cela, nous allons devoir préciser type de données qui sera envoyé via notre formulaire. Ce type est définit par défaut à &lt;em&gt;application/x-www-form-urlencoded&lt;/em&gt; et ne permet pas l'envoie de fichiers. Nous allons le modifier au moyen de l'attribut &lt;em&gt;enctype&lt;/em&gt; de la balise &lt;em&gt;form&lt;/em&gt; et luis donner pour valeur &lt;em&gt;multipart/form-data&lt;/em&gt; ce qui permettra l'envoie de n'importe quel type de données.&lt;/p&gt;


&lt;p&gt;Enfin, pour permettre la sélection du fichier par le client, nous utiliserons un élément de formulaire de type &lt;em&gt;file&lt;/em&gt;.&lt;/p&gt;

&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;&lt;/span&gt;?xml &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt; encoding&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;UTF-8&amp;quot;&lt;/span&gt;?&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
﻿&lt;span style=&quot;color: #00bbdd;&quot;&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Strict//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;html&lt;/span&gt; xmlns&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/span&gt; xml:&lt;span style=&quot;color: #000066;&quot;&gt;lang&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;lang&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;&lt;/span&gt;Formulaire d'upload&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;form&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;post&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;enctype&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;multipart/form-data&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;action&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;upload.php&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&amp;gt;&lt;/span&gt;&lt;/span&gt;S&lt;span style=&quot;color: #ddbb00;&quot;&gt;&amp;amp;eacute;&lt;/span&gt;lectionnez un fichier :
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;file&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fichier&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;submit&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Envoyer&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/span&gt;
 &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Cet exemple de formulaire permet d'envoyer un seul fichier sur le serveur. Ce fichier sera placé dans un répertoire contenant des fichiers temporaires et, s'il ne fait pas l'objet d'un traitement supplémentaire, il sera supprimé à la fin de l'exécution de la requête. C'est pourquoi nous allons devoir faire intervenir PHP.&lt;/p&gt;


&lt;h3&gt;Le script PHP&lt;/h3&gt;

&lt;p&gt;Passons maintenant au script chargé du traitement approprié. Nous allons dans un premier temps en voir une version simple qui autorise tout types de fichiers.&lt;/p&gt;


&lt;p&gt;Lorsque qu'un script reçoit les informations transmises par un formulaire, on utilise habituellement la variable globale &lt;em&gt;$_POST&lt;/em&gt; pour les lire. Cependant, pour les élément de type &lt;em&gt;file&lt;/em&gt;, on devra récupérer les informations concernant le fichiers via la variable &lt;em&gt;$_FILES&lt;/em&gt;. Il s'agit d'un tableau associatif contenant différentes informations concernant les fichiers envoyés. La structure de ce tableau est la suivante&amp;nbsp;:&lt;/p&gt;



&lt;pre&gt;Array
(
    [nom_du_champ_file] =&amp;gt; Array
        (
            [name] =&amp;gt; &quot;MaBelleImage.jpg&quot; // Nom du fichier
            [type] =&amp;gt; &quot;image/jpg&quot; // type de fichier
            [tmp_name] =&amp;gt; &quot;chemin_complet_du_fichier_uploadé&quot; // Emplacement temporaire
            [error] =&amp;gt; 0 // Code d'erreur si erreur il y a
            [size] =&amp;gt; 1000 // Taille du fichier
        )
)&lt;/pre&gt;


&lt;p&gt;A partir de ces informations, nous pourrons effectuer différents contrôles que nous verrons un peu plus tard. Pour le moment, nous allons simplement sauvegarder le fichier envoyé.&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On définit notre répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'./fichiers/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie qu'il est accessible en écriture&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_writable&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Impossible d&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\'&lt;/span&gt;écrire dans le répertoire cible.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie d'abord que des données ont bien été envoyées&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Aucune données'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On finit par déplacer le fichier dans le répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #000066;&quot;&gt;move_uploaded_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'tmp_name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Bien que ce script soit théoriquement fonctionnel, il est très imparfait. En effet, il ne contrôle pas le bon déroulement de l'envoie du fichier au moyen des codes d'erreur pouvant être indiqués dans le tableau $_FILES. En effet, la valeur de ce code nous indique le type d'erreur qui s'est produite durant l'envoie.&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On définit notre répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'./fichiers/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie qu'il est accessible en écriture&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_writable&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Impossible d&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\'&lt;/span&gt;écrire dans le répertoire cible.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie d'abord que des données ont bien été envoyées&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Aucune données'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Vérification du code d'erreur&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'error'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
     &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_INI_SIZE&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_FORM_SIZE&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le fichier dépasse la limite autorisée dans le formulaire HTML !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_PARTIAL&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;L'envoi du fichier a été interrompu pendant le transfert !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_NO_FILE&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le fichier que vous avez envoyé a une taille nulle !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On finit par déplacer le fichier dans le répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #000066;&quot;&gt;move_uploaded_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'tmp_name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Ainsi, ce script ne devrait pas lever d'erreur. A noter que &lt;a href=&quot;http://fr.php.net/manual/fr/features.file-upload.errors.php&quot; hreflang=&quot;fr&quot;&gt;d'autres types d'erreurs&lt;/a&gt; ont été introduit avec les nouvelles versions de PHP. Cependant, il reste assez incomplet. Nous allons maintenant lui ajouter quelques fonctionnalités supplémentaires. Et pour commencer, une indispensable, éviter l'écrasement des fichiers.&lt;/p&gt;


&lt;h4&gt;Éviter l'écrasement de fichier&lt;/h4&gt;

&lt;p&gt;Le problème que risque de poser le script que nous avons vu est l'écrasement de fichiers déjà existant. En effet, si vous envoyez deux fichiers portant le même nom, le premier fichier sera écrasé par le second. Pour remédier à cela, je vous propose une solution assez simple qui consiste à préfixer le nom du fichier d'un chiffre. Il existe d'autres solutions mais celle-ci est assez efficace et durable.&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On définit notre répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'./fichiers/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie qu'il est accessible en écriture&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_writable&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Impossible d&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\'&lt;/span&gt;écrire dans le répertoire cible.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie d'abord que des données ont bien été envoyées&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Aucune données'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Vérification du code d'erreur&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'error'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
     &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_INI_SIZE&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_FORM_SIZE&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le fichier dépasse la limite autorisée dans le formulaire HTML !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_PARTIAL&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;L'envoi du fichier a été interrompu pendant le transfert !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_NO_FILE&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le fichier que vous avez envoyé a une taille nulle !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie si le fichier existe déjà dans le répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_exists&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On utilise une boucle pour incrémenter notre préfixe&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_exists&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'_'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;++&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Arrivé ici, on a trouvé un nom disponible avec un préfixe numérique&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000&quot;&gt;$cible&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'_'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Le fichier n'existe pas dans le répertoire cible,&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Nous pouvons donc utiliser le nom original&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000&quot;&gt;$cible&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On finit par déplacer le fichier dans le répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #000066;&quot;&gt;move_uploaded_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'tmp_name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$cible&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Avec cette nouvelle version, les fichiers ne pourront pas être écrasés. Nous allons maintenant voir comment limiter l'envoie à certains types de fichiers.&lt;/p&gt;


&lt;h4&gt;Limiter les types de fichiers autorisés&lt;/h4&gt;

&lt;p&gt;Pour instaurer cette limitation, on pourrait éventuellement se baser sur l'information de type (Type mime) contenue dans le tableau $_FILES. Cependant, cette information est fournit par le client, le navigateur. La règle d'or en matière de développement web est de ne jamais avoir confiance dans les données transmises par un tiers inconnu. D'autre part, cette information pourra être un peut différente pour un même type de fichier et des navigateurs différents. Pour ces raisons, on ne tiendra pas compte de cette information.&lt;/p&gt;


&lt;p&gt;Idéalement, il faudrait utiliser une méthode consistant à rechercher le type mime à partir du contenu du fichier. Il existe, pour cela la, fonction &lt;a href=&quot;http://fr.php.net/mime_content_type&quot; hreflang=&quot;fr&quot;&gt;mime_content_type()&lt;/a&gt; mais elle est désormais déprécier au profit de &lt;a href=&quot;http://www.php.net/manual/fr/ref.fileinfo.php&quot; hreflang=&quot;fr&quot;&gt;Fileinfo&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Pour faire simple ici, nous baserons notre test sur l'extension du fichier. Pour que cette méthode soit suffisamment sûr, il est important que votre serveur soit correctement configuré pour ne pas exécuter de code côté serveur dans des fichiers ne portant pas une extension propre au langage. On a pu voir, par exemple, des serveurs autorisant l'exécution de code PHP dans fichiers portant l'extension .jpg, ce qui est un peu douteu...&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On définit notre répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'./fichiers/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On créé un tableau contenant les extensions autorisées&lt;/span&gt;
  &lt;span style=&quot;color: #ff0000&quot;&gt;$extOk&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.jpg'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.gif'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie qu'il est accessible en écriture&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_writable&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Impossible d&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\'&lt;/span&gt;écrire dans le répertoire cible.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie d'abord que des données ont bien été envoyées&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Aucune données'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Vérification du code d'erreur&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'error'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
     &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_INI_SIZE&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_FORM_SIZE&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le fichier dépasse la limite autorisée dans le formulaire HTML !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_PARTIAL&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;L'envoi du fichier a été interrompu pendant le transfert !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// UPLOAD_ERR_NO_FILE&lt;/span&gt;
        &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le fichier que vous avez envoyé a une taille nulle !&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
        &lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On lit l'extension du fichier&lt;/span&gt;
  &lt;span style=&quot;color: #ff0000&quot;&gt;$fileExt&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;substr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;-4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie que l'extension est dans le tableau&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// des extensions autorisées&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;in_array&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$fileExt&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$extOk&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Type de fichier non autorisé.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie si le fichier existe déjà dans le répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_exists&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On utilise une boucle pour incrémenter notre préfixe&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_exists&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'_'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;++&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Arrivé ici, on a trouvé un nom disponible avec un préfixe numérique&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000&quot;&gt;$cible&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'_'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Le fichier n'existe pas dans le répertoire cible,&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Nous pouvons donc utiliser le nom original&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000&quot;&gt;$cible&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$dstRep&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On finit par déplacer le fichier dans le répertoire cible&lt;/span&gt;
  &lt;span style=&quot;color: #000066;&quot;&gt;move_uploaded_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_FILES&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fichier'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'tmp_name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$cible&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Le système que nous venons de voir ne permet que de tester les extensions d'une longueur de trois caractère et nécessitera quelques modifications pour tester des extensions plus longue. Cependant, par convention, on se limite à 3 caractères pour l'extension d'un fichier.&lt;/p&gt;


&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Nous avons vu l'upload de fichiers avec PHP et quelques test pour aller un peu plus loin. Permettez moi un conseil, restez prudent avec l'envoie de fichiers car ceci peu ouvrir d'énormes failles sur vos sites. N'hésitez donc pas mettre en œuvre le maximum de test de sécurité sur les données envoyées.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.code-web.org/post/2008/01/14/40-upload-de-fichiers-via-formulaire-avec-php#comment-form</comments>
      <wfw:comment>http://www.code-web.org/post/2008/01/14/40-upload-de-fichiers-via-formulaire-avec-php#comment-form</wfw:comment>
      <wfw:commentRss>http://www.code-web.org/feed/rss2/comments/25</wfw:commentRss>
    						<h3>Abonnement aux commentaires</h3>
						<p>
							<a href="http://www.code-web.org/subscribetocomments?post_id=25">
								<!-- # If the subscriber is logged in -->
																<!-- # If the subscriber is not logged in -->
																	S'abonner pour recevoir les commentaires suivants par email															</a>
						</p>
					  </item>
    
  <item>
    <title>Les Pseudo Frames</title>
    <link>http://www.code-web.org/post/2007/12/27/15-les-pseudo-frames</link>
    <guid isPermaLink="false">urn:md5:ebe173b4a57ff70396beb2a8d9d5cabd</guid>
    <pubDate>Thu, 27 Dec 2007 20:18:00 +0000</pubDate>
    <dc:creator>Thierry Geindre</dc:creator>
        <category>PHP</category>
        <category>accessibilité</category><category>html</category><category>php</category><category>référencement</category>    
    <description>&lt;p&gt;Vous connaissez peut-être les frames. Il s'agit d'un système fournit par le langage html permettant de découper une page en plusieurs autres pages. Bien que présentant un certain nombres d'avantages, ce système apporte également son lot d'inconvénients qui nous pousserons à utiliser une autre méthode que constituent les pseudo frames.&lt;/p&gt;    &lt;h3&gt;Pourquoi utiliser des frames?&lt;/h3&gt;

&lt;p&gt;Comme je le disais, les frames permettent de mettre en place un découpage d'une page en plusieurs autres. Ceci permet de régler certains problèmes de maintenances d'un site. En effet lorsqu'un menu apparaît sur de nombreuses pages, il peut être fastidieux de le modifier sur chacune de ces pages.&lt;/p&gt;


&lt;p&gt;Grâce aux frames, il est possible de n'avoir ce menu que sur une seule page. Les autres pages du site seront toujours affichées accompagnées de ce menu grâce à un système de cadres.&lt;/p&gt;


&lt;p&gt;Cependant, les frames posent un certain nombre de problèmes.&lt;/p&gt;


&lt;h3&gt;Pourquoi ne pas utiliser les frames?&lt;/h3&gt;

&lt;p&gt;En règle générale, il est bon de développer un site Web en respectant une norme la plus strict et la plus récente possible. Le &lt;a href=&quot;http://www.la-grange.net/w3c/xhtml1/&quot; hreflang=&quot;fr&quot;&gt;XHTML 1.0 Strict&lt;/a&gt; est un bon exemple, et cette norme interdit l'utilisation des frames ou frameset. Ceci n'explique pas pourquoi faut-il se priver des frames mais constitue déjà un premier argument.&lt;/p&gt;


&lt;p&gt;Les frames posent tout une série de problèmes&amp;nbsp;:&lt;/p&gt;

&lt;h4&gt;Des problèmes d'accessibilité&lt;/h4&gt;

&lt;p&gt;Un certain nombre de navigateurs sont incapables d'interpréter les frames. En les utilisant, vous réduisez ainsi le nombre potentiel de visiteurs que votre site pourrait accueillir.&lt;/p&gt;

&lt;h4&gt;De référencement&lt;/h4&gt;

&lt;p&gt;On sait aujourd'hui que les bot des différents moteurs de recherche existant sur le Web ne sont pas vraiment friant des frames. De plus, un visiteur qui cliquera sur un résultat d'une recherche pourra arriver directement sur une page sans avoir les frames affichées. Il perdra ainsi le menu et, là, aucune chance pour qu'il visite d'autre pages de votre site.&lt;/p&gt;


&lt;p&gt;Il existe bien un moyen de régler ce second problème à l'aide de java script, mais on en revient alors à des problèmes d'accessibilité.&lt;/p&gt;


&lt;p&gt;Les frames posent encore d'autre problèmes, une petite recherche vous en donnera certainement la liste complète. Nous avons vu ici les principaux.&lt;/p&gt;


&lt;h3&gt;Les pseudo frames&lt;/h3&gt;

&lt;p&gt;Pour palier aux problèmes des frames, il nous faut une solution qui apporte les mêmes avantages sans les inconvénients bien sur. C'est justement là qu'interviennent les pseudo frames. Il s'agit d'un système qui consiste à construire une page à partir de plusieurs fichiers mais côté serveur uniquement. Ainsi, le mécanisme est totalement invisible pour le client qui ne verra qu'une page correctement construite et sans frame.&lt;/p&gt;


&lt;p&gt;Pour ce faire, nous allons devoir utiliser un langage côté serveur. PHP satisfera parfaitement ce besoin, mais il faut tout de même savoir que n'importe quel autre langage côté serveur pourra faire l'affaire suivant le même principe.&lt;/p&gt;


&lt;h4&gt;Fichiers et arborescence&lt;/h4&gt;

&lt;p&gt;Classiquement, on retrouve pour une page quatre parties biens distinctes&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;L'en-tête (header)&lt;/li&gt;
&lt;li&gt;Le pied de page (footer)&lt;/li&gt;
&lt;li&gt;Le menu&lt;/li&gt;
&lt;li&gt;Le contenu de la page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On aura donc 3 fichiers qui seront systématiquement les mêmes pour toutes les pages d'un site, à savoir&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;header.html (L'en-tête)&lt;/li&gt;
&lt;li&gt;footer.html (Le pied de page)&lt;/li&gt;
&lt;li&gt;menu.html (Le menu)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Et un quatrième fichier sera utilisé pour construire une page, il ne s'agira pas du même fichier en fonction de la page que l'on souhaite afficher. Pour structurer un peu l'arborescence de notre site, ou pourra créer deux répertoires. L'un contenant les fichier communs à toute les pages du site et l'autre contenant les différents fichiers qui contiendront les contenus des pages. Ces répertoires pourront être nommés respectivement includes (du verbe To Include (inclure) de l'anglais) et pages.&lt;/p&gt;


&lt;p&gt;En plus de ces répertoires et fichiers, il nous faudra un fichier supplémentaire qui contiendra les instructions de constructions de la page à partir des différents fichiers. Nous utiliserons pour cela un fichier index.php placé à la racine de notre arborescence.&lt;/p&gt;


&lt;p&gt;On obtiendra donc l'arborescence suivante&amp;nbsp;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;index.php&lt;/li&gt;
&lt;li&gt;includes/
&lt;ul&gt;
&lt;li&gt;header.html&lt;/li&gt;
&lt;li&gt;footer.html&lt;/li&gt;
&lt;li&gt;menu.html&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;pages/
&lt;ul&gt;
&lt;li&gt;accueil.html&lt;/li&gt;
&lt;li&gt;autre.html&lt;/li&gt;
&lt;li&gt;etc.html&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bien entendu, d'autres arborescences pourront être mises en place mais celle-ci satisfera la majorité des cas.&lt;/p&gt;


&lt;h4&gt;Contenu des fichiers&lt;/h4&gt;

&lt;p&gt;Excepté le fichier index.php, tout les autres fichiers devront être remplis avec le code html qui compose les pages de votre site. Cependant, vous ne devrez pas y placer exactement le même contenu que si vous aviez utilisé des frames. En effet, il ne faudra pas placer les en-têtes de pages dans chacun des fichiers mais seulement dans header.html. Un exemple sera certainement plus parlant&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;includes/header.html&lt;/p&gt;
&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;&lt;/span&gt;?xml &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt; encoding&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;UTF-8&amp;quot;&lt;/span&gt;?&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
﻿&lt;span style=&quot;color: #00bbdd;&quot;&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Strict//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;html&lt;/span&gt; xmlns&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/span&gt; xml:&lt;span style=&quot;color: #000066;&quot;&gt;lang&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;lang&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;&lt;/span&gt;Le titre de la page&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;link&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;rel&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;stylesheet&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;/dotclear/themes/CodeWeb/style.css&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;media&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;screen&amp;quot;&lt;/span&gt; 
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Comme nous l'avons déjà vu, notre script index.php vas se charger de construire &lt;strong&gt;une seule page&lt;/strong&gt; à partir des fichiers que nous avons énuméré. Il ne s'agit donc plus de créer plusieurs pages et de les afficher dans des cadres. Ainsi, le code d'en-tête (&amp;lt;head&amp;gt;) ne devra se trouver que dans le fichier header.html et dans aucun autre. De même, le code qui sera destiné à fermer le &amp;lt;body&amp;gt; et &amp;lt;html&amp;gt; ne devra se trouver que dans le fichier footer.html.&lt;/p&gt;


&lt;p&gt;includes/footer.html&lt;/p&gt;
&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Notre menu pourra être formé d'une simple liste&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;includes/menu.html&lt;/p&gt;
&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;ul&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;menu&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;li&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;a&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;index.php&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Accueil&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;li&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;a&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;index.php?page=autre&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Autre&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Il ne nous restera ensuite plus qu'a créer autant de pages que nous le souhaitons dans le répertoire pages. Le minimum serait une page index.html qui sera celle qui sera affichée par défaut. C'est à dire lorsque la page demandée au script index.php ne correspond à aucune page connue ou lorsqu'aucune page n'est demandée. On créera ici une page supplémentaire nommée autre.html pour coller au menu que je vous proposé en exemple.&lt;/p&gt;


&lt;p&gt;pages/index.html&lt;/p&gt;
&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;/span&gt;Accueil&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;Bienvenue sur l'accueil.&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;pages/autre.html&lt;/p&gt;
&lt;pre class=&quot;html&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;/span&gt;Autre&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/span&gt;Une autre page.&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Construction de la page&lt;/h4&gt;

&lt;p&gt;Comme nous l'avons vu, c'est le script index.php placé à la racine de notre arborescence qui sera chargé de construire une page à partir de tout les fichiers dont il dispose. Ainsi, pour afficher une page on fera toujours appel au fichier index.php avec un paramètre page dans l'URL (méthode GET). On pourra ensuite lire ce paramètre dans notre script via la variable $_GET['page'].&lt;/p&gt;


&lt;p&gt;Par exemple, pour afficher la page autre.html, on utilisera le lien suivant&amp;nbsp;: http://www.site.com/index.php?page=autre Il s'agit du second lien proposé dans le menu d'exemple.&lt;/p&gt;


&lt;p&gt;index.php&lt;/p&gt;
&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On définit une liste de pages autorisées au moyen d'un tableau&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Vous devrez ajouter toutes les pages se trouvant dans le répertoire&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// pages pour les rendre accessibles.&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Vous pouvez également automatiser la génération de ce tableau&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// en lisant le contenu du répertoire pages/&lt;/span&gt;
  &lt;span style=&quot;color: #ff0000&quot;&gt;$pagesOk&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'index'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'autre'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On commence par lire la page demandée&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Si ce n'est pas vide&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;empty&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_GET&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'page'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On lit la valeur demandée&lt;/span&gt;
    &lt;span style=&quot;color: #ff0000&quot;&gt;$page&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$_GET&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'page'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;
   &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Sinon on utiliser index comme page par défaut&lt;/span&gt;
   &lt;span style=&quot;color: #ff0000&quot;&gt;$page&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'index'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On vérifie que la page demandée se trouve dans les pages autorisées&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #000066;&quot;&gt;in_array&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$page&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$pagesOk&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Elle n'y est pas, dans ce cas on peut renvoyer une erreur 404&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;HTTP/1.0 404 Not Found&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On stop l'exécution du script ici&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;exit&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Arrivé ici, on sait que la page demandée existe forcément.&lt;/span&gt;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On va donc pouvoir commencer la construction de la page.&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On commence par inclure l'entête&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'./includes/header.html'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Puis le menu&lt;/span&gt;
  &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'./includ