<?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 => 'es',
  ),
  'this' => 
  array (
    0 => 'function.readfile.php',
    1 => 'readfile',
    2 => 'Muestra un fichero',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Funciones del Sistema de Archivos',
  ),
  'prev' => 
  array (
    0 => 'function.popen.php',
    1 => 'popen',
  ),
  'next' => 
  array (
    0 => 'function.readlink.php',
    1 => 'readlink',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'es',
    'path' => 'reference/filesystem/functions/readfile.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.readfile" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">readfile</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">readfile</span> &mdash; <span class="dc-title">Muestra un fichero</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.readfile-description">
  <h3 class="title">Descripción</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>readfile</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.boolean.php" class="type bool">bool</a></span> <code class="parameter">$use_include_path</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></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.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Lee un fichero y lo envía al buffer de salida.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.readfile-parameters">
  <h3 class="title">Parámetros</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       El fichero a leer.
      </p>
     </dd>
    
    
     <dt><code class="parameter">use_include_path</code></dt>
     <dd>
      <p class="para">
       Puede utilizarse el segundo argumento opcional
       para explorar el directorio <a href="ini.core.php#ini.include-path" class="link">include_path</a>,
       pasando el valor de <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">Un <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> de
 <a href="stream.contexts.php" class="link">contexto de flujo</a>.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.readfile-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="para">
   Devuelve el número de bytes leídos desde el fichero
   en caso de éxito,  o <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si ocurre un error
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.readfile-errors">
  <h3 class="title">Errores/Excepciones</h3>
  <p class="para">
En caso de fallo, se emitirá una advertencia de tipo <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
</p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.readfile-examples">
  <h3 class="title">Ejemplos</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Ejemplo #1 Forzar la descarga utilizando <span class="function"><strong>readfile()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$file </span><span style="color: #007700">= </span><span style="color: #DD0000">'monkey.gif'</span><span style="color: #007700">;<br /><br />if (</span><span style="color: #0000BB">file_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">)) {<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Description: File Transfer'</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type: application/octet-stream'</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Disposition: attachment; filename="'</span><span style="color: #007700">.</span><span style="color: #0000BB">basename</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">).</span><span style="color: #DD0000">'"'</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Expires: 0'</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Cache-Control: must-revalidate'</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Pragma: public'</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Length: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">filesize</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">));<br />    </span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">);<br />    exit;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Resultado del ejemplo anterior es similar a:</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/e88cefb5c3fca5060e2490b9763c4433-readfile.png" alt="Ventana de apertura / guardado" width="319" height="245" />
     </div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.readfile-notes">
  <h3 class="title">Notas</h3>

  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    <span class="function"><strong>readfile()</strong></span> no presentará problemas de memoria,
    incluso al enviar ficheros grandes. Si se encuentran este tipo
    de problemas, asegúrese de que el buffer de salida está desactivado
    con la función <span class="function"><a href="function.ob-get-level.php" class="function">ob_get_level()</a></span>.
   </p>
  </p></blockquote>

  <div class="tip"><strong class="tip">Sugerencia</strong><p class="simpara">
 Puede utilizar una URL como nombre de archivo con esta función, si el
 <a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">gestor fopen</a> ha sido activado. Véase <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>
 para más detalles sobre cómo especificar el nombre del archivo. Consulte
 <a href="wrappers.php" class="xref">Protocolos y Envolturas soportados</a> para más información sobre las capacidades de los diferentes gestores,
 las notas sobre su uso, así como la información sobre las variables predefinidas que proporcionan.
</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.readfile-seealso">
  <h3 class="title">Ver también</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.fpassthru.php" class="function" rel="rdfs-seeAlso">fpassthru()</a> - Muestra el resto del fichero</span></li>
    <li><span class="function"><a href="function.file.php" class="function" rel="rdfs-seeAlso">file()</a> - Lee el fichero y devuelve el resultado en un array</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - Abre un fichero o un URL</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.require.php" class="function" rel="rdfs-seeAlso">require</a> - require</span></li>
    <li><span class="function"><a href="function.virtual.php" class="function" rel="rdfs-seeAlso">virtual()</a> - Efect&uacute;a una subpetici&oacute;n Apache</span></li>
    <li><span class="function"><a href="function.file-get-contents.php" class="function" rel="rdfs-seeAlso">file_get_contents()</a> - Lee todo un fichero en una cadena</span></li>
    <li><a href="wrappers.php" class="xref">Protocolos y Envolturas soportados</a></li>
   </ul>
  </p>
 </div>


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