<?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 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.readfile.php',
    1 => 'readfile',
    2 => 'Gibt eine Datei aus',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Dateisystem',
  ),
  'prev' => 
  array (
    0 => 'function.popen.php',
    1 => 'popen',
  ),
  'next' => 
  array (
    0 => 'function.readlink.php',
    1 => 'readlink',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    '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">Gibt eine Datei aus</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.readfile-description">
  <h3 class="title">Beschreibung</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">
   Liest den Inhalt einer Datei und schreibt ihn in den Ausgabepuffer.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.readfile-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       Der Name der Datei, die gelesen werden soll.
      </p>
     </dd>
    
    
     <dt><code class="parameter">use_include_path</code></dt>
     <dd>
      <p class="para">
       Sie können optional den zweiten Parameter benutzen und diesen auf
       <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> setzen, wenn Sie auch im
       <a href="ini.core.php#ini.include-path" class="link">include_path</a> nach der Datei
       suchen möchten.
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">Eine <a href="stream.contexts.php" class="link">Stream-Kontext</a>-<span class="type"><a href="language.types.resource.php" class="link">Ressource</a></span>.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.readfile-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt bei Erfolg die Anzahl der gelesenen Bytes einer Datei zurück.
   Bei einem Fehler wird <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> zurückgegeben.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.readfile-errors">
  <h3 class="title">Fehler/Exceptions</h3>
  <p class="para">
Im Fehlerfall wird eine <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> ausgegeben.
</p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.readfile-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 Einen Download unter Verwendung von <span class="function"><strong>readfile()</strong></span> erzwingen</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>Das oben gezeigte Beispiel erzeugt
eine ähnliche Ausgabe wie:</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/e88cefb5c3fca5060e2490b9763c4433-readfile.png" alt="Öffnen/Speichern-Dialog" width="319" height="245" />
     </div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.readfile-notes">
  <h3 class="title">Anmerkungen</h3>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    <span class="function"><strong>readfile()</strong></span> weist für sich allein keine Speicherprobleme
    auf, selbst wenn große Dateien gesendet werden. Wenn Sie auf einen
    out-of-memory-Fehler treffen, stellen Sie mit
    <span class="function"><a href="function.ob-get-level.php" class="function">ob_get_level()</a></span> sicher, dass die Ausgabepufferung
    deaktiviert ist.
   </p>
  </p></blockquote>
  <div class="tip"><strong class="tip">Tipp</strong><p class="simpara">Wenn
<a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">fopen wrappers</a> aktiviert ist, kann
mit dieser Funktion eine URL als Dateiname verwendet werden. Mehr Details dazu,
wie der Dateiname angeben werden muss, sind bei <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> zu
finden. Eine Liste der unterstützten URL-Protokolle, die Fähigkeiten der
verschiedenen Wrapper, Hinweise zu deren Verwendung und Informationen zu den
eventuell vorhandenen vordefinierten Variablen sind unter
<a href="wrappers.php" class="xref">Unterst&uuml;tzte Protokolle und Wrapper</a> zu finden.</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.readfile-seealso">
  <h3 class="title">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.fpassthru.php" class="function" rel="rdfs-seeAlso">fpassthru()</a> - Gibt alle verbleibenden Daten eines Dateizeigers aus</span></li>
    <li><span class="function"><a href="function.file.php" class="function" rel="rdfs-seeAlso">file()</a> - Liest eine komplette Datei in ein Array</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - &Ouml;ffnet eine Datei oder 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> - F&uuml;hrt eine Apache-Unteranfrage durch</span></li>
    <li><span class="function"><a href="function.file-get-contents.php" class="function" rel="rdfs-seeAlso">file_get_contents()</a> - Liest die gesamte Datei in einen String</span></li>
    <li><a href="wrappers.php" class="xref">Unterst&uuml;tzte Protokolle und Wrapper</a></li>
   </ul>
  </p>
 </div>


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