Is it possible to read files from remote servers or other domains? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Is it possible to read files from remote servers or other domains?

for example our domain is: example.com but we need to read a file from other domains like: sample.com

19th Jan 2016, 12:30 PM
Hossein Ghassemi Rad
Hossein Ghassemi Rad - avatar
2 Respostas
+ 2
As long as allow_url_fopen is enabled in php.ini, you can use HTTP and FTP URLs with most of the functions that take a filename as a parameter. In addition, URLs can be used with the include, include_once, require and require_once statements (since PHP 5.2.0, allow_url_include must be enabled for these) Example. Getting the title of a remote page: <?php $file = fopen ("http://www.example.com/", "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 (preg_match ("@\<title\>(.*)\</title\>@i", $line, $out)) { $title = $out[1]; break; } } fclose($file); ?>
16th May 2017, 10:57 AM
Krzysztof Przybylowski
Krzysztof Przybylowski - avatar
+ 1
you can use, file_get_contents() function. $remfile=file_get_contents('www.google.com');
24th Jan 2016, 11:41 AM
Amin Maleki
Amin Maleki - avatar