<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filesystem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.file.php',
    1 => 'file',
    2 => 'Lit le fichier et renvoie le r&eacute;sultat dans un tableau',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Fonctions sur les syst&egrave;mes de fichiers',
  ),
  'prev' => 
  array (
    0 => 'function.fgetss.php',
    1 => 'fgetss',
  ),
  'next' => 
  array (
    0 => 'function.file-exists.php',
    1 => 'file_exists',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/filesystem/functions/file.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.file" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">file</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">file</span> &mdash; <span class="dc-title">Lit le fichier et renvoie le résultat dans un tableau</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.file-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>file</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span></span> <code class="parameter">$context</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Lit le fichier et renvoie le résultat dans un tableau.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Il est possible d&#039;utiliser la fonction <span class="function"><a href="function.file-get-contents.php" class="function">file_get_contents()</a></span>
    pour retourner le contenu d&#039;un fichier dans une <a href="language.types.string.php" class="link">chaîne de caractères</a>.
   </p>
  </p></blockquote>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.file-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       Chemin vers le fichier.
      </p>
      <div class="tip"><strong class="tip">Astuce</strong><p class="simpara">
 Vous pouvez utiliser une URL comme nom de fichier avec cette fonction, si le
 <a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">gestionnaire fopen</a> a été activé. Voyez <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>
 pour plus de détails sur la façon de spécifier le nom du fichier. Reportez-vous aux
 <a href="wrappers.php" class="xref">Liste des protocoles et des gestionnaires support&eacute;s</a> pour plus d&#039;informations sur les capacités des différents gestionnaires,
 les notes sur leur utilisation, ainsi que les informations sur les variables prédéfinies qu&#039;elles fournissent.
</p></div>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       Le paramètre optionnel <code class="parameter">flags</code> peut être
       une ou plusieurs des constantes suivantes :
       <dl>
        
         <dt>
          <strong><code><a href="filesystem.constants.php#constant.file-use-include-path">FILE_USE_INCLUDE_PATH</a></code></strong>
         </dt>
         <dd>
          <span class="simpara">
           Recherche le fichier dans l&#039;<a href="ini.core.php#ini.include-path" class="link">include_path</a>.
          </span>
         </dd>
        
        
         <dt>
          <strong><code><a href="filesystem.constants.php#constant.file-ignore-new-lines">FILE_IGNORE_NEW_LINES</a></code></strong>
         </dt>
         <dd>
          <span class="simpara">
           N&#039;ajoute pas de nouvelle ligne à la fin de chaque élément du tableau.
          </span>
         </dd>
        
        
         <dt>
          <strong><code><a href="filesystem.constants.php#constant.file-skip-empty-lines">FILE_SKIP_EMPTY_LINES</a></code></strong>
         </dt>
         <dd>
          <span class="simpara">
           Ignore les lignes vides.
          </span>
         </dd>
        
        
         <dt>
          <strong><code><a href="filesystem.constants.php#constant.file-no-default-context">FILE_NO_DEFAULT_CONTEXT</a></code></strong>
         </dt>
         <dd>
          <span class="simpara">
           N&#039;utilise pas le contexte par défaut.
          </span>
         </dd>
        
       </dl>
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">
 Une <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> de <a href="stream.contexts.php" class="link">contexte de flux</a>.
</span></p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.file-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne le fichier dans un tableau.
   Chaque élément du tableau correspond à une ligne du fichier,
   et les retours-chariot sont placés en fin de ligne. Si une erreur
   survient, <span class="function"><strong>file()</strong></span> retournera <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Chaque ligne du tableau résultant inclura une fin de ligne, à moins
    que <strong><code><a href="filesystem.constants.php#constant.file-ignore-new-lines">FILE_IGNORE_NEW_LINES</a></code></strong> soit utilisé.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">
 Si PHP ne reconnaît pas correctement les fins de lignes lors de la lecture de fichiers qui ont été créés ou lus sur
 un Macintosh, l&#039;activation de l&#039;option de configuration
 <a href="filesystem.configuration.php#ini.auto-detect-line-endings" class="link">auto_detect_line_endings</a> peut régler le problème.
</span></p></blockquote>
 </div>

 
 <div class="refsect1 errors" id="refsect1-function.file-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="simpara">
   À partir de PHP 8.3.0, une exception <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span>
   est levée si le <code class="parameter">flags</code> contient des valeurs invalides,
   comme <strong><code><a href="filesystem.constants.php#constant.file-append">FILE_APPEND</a></code></strong>.
  </p>
  <p class="para">
   Émet une erreur de niveau <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> si le fichier 
   n&#039;existe pas.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.file-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       Une exception <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> est levée pour
       toute valeur invalide du <code class="parameter">flags</code>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.file-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>file()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Lit une page web dans un tableau.<br /></span><span style="color: #0000BB">$lines </span><span style="color: #007700">= </span><span style="color: #0000BB">file</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com/'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Affiche toutes les lignes du tableau comme code HTML, avec les numéros de ligne<br /></span><span style="color: #007700">foreach (</span><span style="color: #0000BB">$lines </span><span style="color: #007700">as </span><span style="color: #0000BB">$line_num </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$line</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"Line #&lt;b&gt;</span><span style="color: #007700">{</span><span style="color: #0000BB">$line_num</span><span style="color: #007700">}</span><span style="color: #DD0000">&lt;/b&gt; : " </span><span style="color: #007700">. </span><span style="color: #0000BB">htmlspecialchars</span><span style="color: #007700">(</span><span style="color: #0000BB">$line</span><span style="color: #007700">) . </span><span style="color: #DD0000">"&lt;br /&gt;\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// Utilisation de drapeau<br /></span><span style="color: #0000BB">$trimmed </span><span style="color: #007700">= </span><span style="color: #0000BB">file</span><span style="color: #007700">(</span><span style="color: #DD0000">'somefile.txt'</span><span style="color: #007700">, </span><span style="color: #0000BB">FILE_IGNORE_NEW_LINES </span><span style="color: #007700">| </span><span style="color: #0000BB">FILE_SKIP_EMPTY_LINES</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.file-notes">
  <h3 class="title">Notes</h3>
  <div class="warning"><strong class="warning">Avertissement</strong><p class="para">
 Lorsque SSL est utilisé, le serveur IIS de Microsoft violera le protocole en fermant la connexion sans
 envoyer un indicateur <code class="literal">close_notify</code>. PHP le reportera en tant que &quot;SSL: Fatal Protocol Error&quot;
 quand vous arrivez à la fin des données. Pour contourner ce le niveau de la directive
 <a href="errorfunc.configuration.php#ini.error-reporting" class="link">error_reporting</a> doit être baissée pour ne pas inclure les avertissements.
 PHP peut détecter automatiquement les serveur IIS bogué lors de l&#039;ouverture
 du flux en utilisant <code class="literal">https://</code> et supprimera l&#039;avertissement.
 Lors de l&#039;utilisation de <span class="function"><a href="function.fsockopen.php" class="function">fsockopen()</a></span> pour créer un socket <code class="literal">ssl://</code>,
 c&#039;est au développeur de détecter et supprimer l&#039;avertissement.
</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.file-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.file-get-contents.php" class="function" rel="rdfs-seeAlso">file_get_contents()</a> - Lit tout un fichier dans une cha&icirc;ne</span></li>
    <li><span class="function"><a href="function.readfile.php" class="function" rel="rdfs-seeAlso">readfile()</a> - Affiche un fichier</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - Ouvre un fichier ou une URL</span></li>
    <li><span class="function"><a href="function.fsockopen.php" class="function" rel="rdfs-seeAlso">fsockopen()</a> - Ouvre un socket de connexion Internet ou Unix</span></li>
    <li><span class="function"><a href="function.popen.php" class="function" rel="rdfs-seeAlso">popen()</a> - Cr&eacute;e un processus de pointeur de fichier</span></li>
    <li><span class="function"><a href="function.include.php" class="function" rel="rdfs-seeAlso">include</a> - include</span></li>
    <li><span class="function"><a href="function.stream-context-create.php" class="function" rel="rdfs-seeAlso">stream_context_create()</a> - Cr&eacute;e un contexte de flux</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>