Introduction
In this article I will explain Remote files in PHP. To open or read a file on a remote server and transfer output data you can use the data in a query. First of all enable "allow_url_fopen" in PHP.ini then use HTTP and FTP function URLs with some functions passed as a parameter as a filename. URLs can be used with include(), include_once(), require(), require_once() statements. You can read remote files in one of three ways using PHP.
Example 1
Here you can get the title of a remote page and also write to files on a FTP server using this example:
<?php
$f
=
fopen
("http://www.csharpcorner.com/",
"r");
if
(!$f)
{
echo
"<p>Unable to open remote file";
exit;
}
while
(!feof
($f))
{
$line
=
fgets
($f,
1024);
if
(preg_match
("@\<title\>(.*)\</title\>@i",
$line,
$out))
{
$tpage
=
$out[1];
break;
}
}
fclose($f);
?>
Example 2
You can read the contents of a remote file using this example:
<?php
$f
=
fopen("http://www.csharpcorner.com/",
"rb");
$content = '';
while (!feof($f))
{
$content .= fread($f, 8192);
}
fclose($f);
?>

Comments
Join the conversation! Your thoughts help the community grow.