2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2002-09-24 02:53:08 +00:00
|
|
|
<!-- $Revision: 1.5 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
|
|
|
|
<refentry id="function.fopen">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>fopen</refname>
|
|
|
|
<refpurpose>Opens file or URL</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
<methodsynopsis>
|
|
|
|
<type>int</type><methodname>fopen</methodname>
|
|
|
|
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
|
|
|
|
<methodparam><type>string</type><parameter>mode</parameter></methodparam>
|
|
|
|
<methodparam choice="opt"><type>int</type><parameter>use_include_path</parameter></methodparam>
|
2002-07-14 18:56:44 +00:00
|
|
|
<methodparam choice="opt"><type>resource</type><parameter>zcontext</parameter></methodparam>
|
2002-04-15 00:12:54 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<simpara>
|
2002-09-24 02:53:08 +00:00
|
|
|
<function>fopen</function> binds a named resource, specified
|
|
|
|
by <parameter>filename</parameter>, to a stream. If
|
|
|
|
<parameter>filename</parameter> is of the form "scheme://...",
|
|
|
|
it is assumed to be a URL and PHP will search for a protocol
|
|
|
|
handler (also known as a wrapper) for that scheme. If no
|
|
|
|
wrappers for that protocol are registered, PHP will emit
|
|
|
|
a notice to help you track potential problems in your script
|
|
|
|
and then continue as though <parameter>filename</parameter>
|
|
|
|
specifies a regular file.
|
2002-04-15 00:12:54 +00:00
|
|
|
</simpara>
|
|
|
|
<simpara>
|
2002-09-24 02:53:08 +00:00
|
|
|
If PHP has decided that <parameter>filename</parameter> specifies
|
|
|
|
a local file, then it will try to open a stream on that file.
|
|
|
|
The file must be accessible to PHP, so you need to ensure that
|
|
|
|
the file access permissions allow this access.
|
|
|
|
If you have enabled <link linkend="ini.safe-mode">safe_mode</link>,
|
|
|
|
or <link linkend="ini.open-basedir">open_basedir</link> further
|
|
|
|
restrictions may apply.
|
2002-04-15 00:12:54 +00:00
|
|
|
</simpara>
|
|
|
|
<simpara>
|
2002-09-24 02:53:08 +00:00
|
|
|
If PHP has decided that <parameter>filename</parameter> specifies
|
|
|
|
a registered protocol, and that protocol is registered as a
|
|
|
|
network URL, PHP will check to make sure that
|
|
|
|
<link linkend="ini.allow-url-fopen">allow_url_fopen</link> is
|
|
|
|
enabled. If it is switched off, PHP will emit a warning and
|
|
|
|
the fopen call will fail.
|
2002-04-15 00:12:54 +00:00
|
|
|
</simpara>
|
2002-09-24 02:53:08 +00:00
|
|
|
<note>
|
|
|
|
<simpara>
|
|
|
|
The list of supported protocols can be found in <xref linkend="wrappers"/>.
|
|
|
|
</simpara>
|
|
|
|
</note>
|
2002-04-15 00:12:54 +00:00
|
|
|
<para>
|
2002-09-24 02:53:08 +00:00
|
|
|
<parameter>mode</parameter> specifies the type of access you
|
|
|
|
require to the stream. It may be any of the following:
|
2002-04-15 00:12:54 +00:00
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'r' - Open for reading only; place the file pointer at the
|
|
|
|
beginning of the file.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'r+' - Open for reading and writing; place the file pointer at
|
|
|
|
the beginning of the file.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'w' - Open for writing only; place the file pointer at the
|
|
|
|
beginning of the file and truncate the file to zero length.
|
|
|
|
If the file does not exist, attempt to create it.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'w+' - Open for reading and writing; place the file pointer at
|
|
|
|
the beginning of the file and truncate the file to zero
|
|
|
|
length. If the file does not exist, attempt to create it.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'a' - Open for writing only; place the file pointer at the end
|
|
|
|
of the file. If the file does not exist, attempt to create
|
|
|
|
it.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<simpara>
|
|
|
|
'a+' - Open for reading and writing; place the file pointer at
|
|
|
|
the end of the file. If the file does not exist, attempt to
|
|
|
|
create it.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
The <parameter>mode</parameter> may contain the letter
|
|
|
|
'b'. This is useful only on systems which differentiate between
|
|
|
|
binary and text files (i.e. Windows. It's useless on Unix).
|
2002-09-24 02:53:08 +00:00
|
|
|
If not needed, this will be ignored. You are encouraged to
|
|
|
|
include the 'b' flag in order to make your scripts more portable.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
<para>
|
2002-07-14 18:56:44 +00:00
|
|
|
The optional third <parameter>use_include_path</parameter> parameter
|
|
|
|
can be set to '1' or &true; if you want to search for the file in
|
|
|
|
the <link linkend="ini.include-path">include_path</link>, too.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The optional fourth <parameter>zcontext</parameter> is used for
|
|
|
|
specifying tuning parameters and callbacks.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
2002-09-24 02:53:08 +00:00
|
|
|
<simpara>
|
|
|
|
If the open fails, the function returns &false;.
|
|
|
|
</simpara>
|
2002-04-15 00:12:54 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>fopen</function> example</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2002-07-14 18:56:44 +00:00
|
|
|
<?php
|
2002-04-15 00:12:54 +00:00
|
|
|
$fp = fopen ("/home/rasmus/file.txt", "r");
|
|
|
|
$fp = fopen ("/home/rasmus/file.gif", "wb");
|
|
|
|
$fp = fopen ("http://www.example.com/", "r");
|
|
|
|
$fp = fopen ("ftp://user:password@example.com/", "w");
|
2002-07-14 18:56:44 +00:00
|
|
|
?>
|
2002-04-15 00:12:54 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
<simpara>
|
|
|
|
If you are experiencing problems with reading and writing to
|
|
|
|
files and you're using the server module version of PHP, remember
|
|
|
|
to make sure that the files and directories you're using are
|
|
|
|
accessible to the server process.
|
|
|
|
</simpara>
|
|
|
|
<para>
|
|
|
|
On the Windows platform, be careful to escape any backslashes
|
|
|
|
used in the path to the file, or use forward slashes.
|
|
|
|
<informalexample>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2002-07-14 18:56:44 +00:00
|
|
|
<?php
|
2002-04-15 00:12:54 +00:00
|
|
|
$fp = fopen ("c:\\data\\info.txt", "r");
|
2002-07-14 18:56:44 +00:00
|
|
|
?>
|
2002-04-15 00:12:54 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</informalexample>
|
|
|
|
</para>
|
|
|
|
<simpara>
|
2002-09-24 02:53:08 +00:00
|
|
|
See also <xref linkend="wrappers"/>,
|
2002-09-16 18:13:37 +00:00
|
|
|
<function>fclose</function>,
|
2002-07-14 18:56:44 +00:00
|
|
|
<function>fgets</function>,
|
2002-04-15 00:12:54 +00:00
|
|
|
<function>fsockopen</function>,
|
2002-07-14 18:56:44 +00:00
|
|
|
<function>file</function>,
|
|
|
|
<function>file_exists</function>,
|
|
|
|
<function>is_readable</function>,
|
2002-04-15 00:12:54 +00:00
|
|
|
<function>socket_set_timeout</function>, and
|
|
|
|
<function>popen</function>.
|
|
|
|
</simpara>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
<!-- 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
|
|
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
|
|
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
|
|
|
|
-->
|