打开文件URL并在PHP中读取它?

时间:2014-10-04 05:33:33

标签: php file fopen

给定指向文件的URL,如何打开它并阅读PHP中的内容?

$file = fopen("http://www.alinktomyfile.com/kasfafa", "r");

此行有错误。 docs说使用stream_get_contents()作为URL,但是我收到错误:

$file_contents = stream_get_contents($file);
fclose($file);

错误:

警告:stream_get_contents()期望参数1为资源,在第24行/Users/donald/Desktop/php_boilerplate.php中给出null

1 个答案:

答案 0 :(得分:0)

尝试file_get_contents()

$file = file_get_contents("http://www.alinktomyfile.com/kasfafa");