2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 07:05:15 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.readfile">
|
2007-02-03 08:13:44 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>readfile</refname>
|
|
|
|
<refpurpose>Outputs a file</refpurpose>
|
|
|
|
</refnamediv>
|
2007-09-15 02:44:00 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2007-02-03 08:13:44 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<type>int</type><methodname>readfile</methodname>
|
|
|
|
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
|
2009-01-16 16:14:26 +00:00
|
|
|
<methodparam choice="opt"><type>bool</type><parameter>use_include_path</parameter><initializer>false</initializer></methodparam>
|
2007-02-03 08:13:44 +00:00
|
|
|
<methodparam choice="opt"><type>resource</type><parameter>context</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
Reads a file and writes it to the output buffer.
|
|
|
|
</para>
|
2007-09-15 02:44:00 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>filename</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The filename being read.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>use_include_path</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
You can use the optional second parameter and set it to &true;, if
|
|
|
|
you want to search for the file in the <link
|
|
|
|
linkend="ini.include-path">include_path</link>, too.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>context</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
A context stream <type>resource</type>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2007-02-03 08:13:44 +00:00
|
|
|
<para>
|
|
|
|
Returns the number of bytes read from the file. If an error
|
|
|
|
occurs, &false; is returned and unless the function was called as
|
|
|
|
@<function>readfile</function>, an error message is printed.
|
|
|
|
</para>
|
2007-09-15 02:44:00 +00:00
|
|
|
</refsect1>
|
|
|
|
|
2008-10-13 19:26:50 +00:00
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>Forcing a download using <function>readfile</function></title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$file = 'monkey.gif';
|
|
|
|
|
2008-10-14 15:10:17 +00:00
|
|
|
if (file_exists($file)) {
|
2008-10-13 19:26:50 +00:00
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
header('Content-Disposition: attachment; filename='.basename($file));
|
|
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
header('Expires: 0');
|
|
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
|
|
header('Pragma: public');
|
|
|
|
header('Content-Length: ' . filesize($file));
|
|
|
|
ob_clean();
|
|
|
|
flush();
|
|
|
|
readfile($file);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
&example.outputs.similar;
|
|
|
|
<mediaobject>
|
2010-01-08 13:59:09 +00:00
|
|
|
<alt>Open / Save dialogue</alt>
|
2008-10-13 19:26:50 +00:00
|
|
|
<imageobject>
|
2009-02-16 11:38:14 +00:00
|
|
|
<imagedata fileref="en/reference/filesystem/figures/readfile.png"/>
|
2008-10-13 19:26:50 +00:00
|
|
|
</imageobject>
|
|
|
|
</mediaobject>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2007-09-15 02:44:00 +00:00
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
|
|
|
|
2007-02-03 08:13:44 +00:00
|
|
|
&tip.fopen-wrapper;
|
|
|
|
¬e.context-support;
|
2007-09-15 02:44:00 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2007-02-03 08:13:44 +00:00
|
|
|
<para>
|
2007-09-15 02:44:00 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>fpassthru</function></member>
|
|
|
|
<member><function>file</function></member>
|
|
|
|
<member><function>fopen</function></member>
|
|
|
|
<member><function>include</function></member>
|
|
|
|
<member><function>require</function></member>
|
|
|
|
<member><function>virtual</function></member>
|
|
|
|
<member><function>file_get_contents</function></member>
|
|
|
|
<member><xref linkend="wrappers"/></member>
|
|
|
|
</simplelist>
|
2007-02-03 08:13:44 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-09-15 02:44:00 +00:00
|
|
|
|
2007-02-03 08:13:44 +00:00
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2002-04-15 00:12:54 +00:00
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|