mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00

Remove duplicated security information. (Whoops.) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@11547 c90b9560-bf6c-de11-be94-00142212c4b1
98 lines
2.8 KiB
Text
98 lines
2.8 KiB
Text
<chapter id="features.remote-files">
|
|
<title>Using remote files</title>
|
|
|
|
<para>
|
|
As long as support for the "URL fopen wrapper" is enabled when
|
|
you configure PHP (which it is unless you explicitly pass the
|
|
<option>--disable-url-fopen-wrapper</option> flag to configure),
|
|
you can use HTTP and FTP URLs with most functions that take a
|
|
filename as a parameter, including the <function>require</function>
|
|
and <function>include</function> statements.
|
|
|
|
<note>
|
|
<para>
|
|
You can't use remote files in <function>include</function> and
|
|
<function>require</function> statements on Windows.
|
|
</note>
|
|
|
|
<para>
|
|
For example, you can use this to open a file on a remote web server,
|
|
parse the output for the data you want, and then use that data in a
|
|
database query, or simply to output it in a style matching the rest
|
|
of your website.
|
|
|
|
<para>
|
|
<example>
|
|
<title>Getting the title of a remote page</title>
|
|
<programlisting>
|
|
<?php
|
|
$file = fopen("http://www.php.net/", "r");
|
|
if (!$file) {
|
|
echo "<p>Unable to open remote file.\n";
|
|
exit;
|
|
}
|
|
while (!feof($file)) {
|
|
$line = fgets($file, 1024);
|
|
/* This only works if the title and its tags are on one line. */
|
|
if (eregi("<title>(.*)</title>", $line, $out)) {
|
|
$title = $out[1];
|
|
break;
|
|
}
|
|
}
|
|
fclose($file);
|
|
?>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<para>
|
|
You can also write to files on an FTP as long you connect as a user
|
|
with the correct access rights, and the file doesn't exist already.
|
|
To connect as a user other than 'anonymous', you need to specify
|
|
the username (and possibly password) within the URL, such as
|
|
'ftp://user:password@ftp.example.com/path/to/file'. (You can use the
|
|
same sort of syntax to access files via HTTP when they require Basic
|
|
authentication.)
|
|
|
|
<para>
|
|
<example>
|
|
<title>Storing data on a remote server</title>
|
|
<programlisting>
|
|
<?php
|
|
$file = fopen("ftp://ftp.php.net/incoming/outputfile", "w");
|
|
if (!$file) {
|
|
echo "<p>Unable to open remote file for writing.\n";
|
|
exit;
|
|
}
|
|
/* Write the data here. */
|
|
fputs($file, "$HTTP_USER_AGENT\n");
|
|
fclose($file);
|
|
?>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<note>
|
|
<para>
|
|
You might get the idea from the example above to use this technique to
|
|
write to a remote log, but as mentioned above, you can only write to
|
|
a new file using the URL fopen() wrappers. To do distributed logging
|
|
like that, you should take a look at <function>syslog</function>.
|
|
</note>
|
|
|
|
</chapter>
|
|
|
|
<!-- 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
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
-->
|