【发布时间】:2014-10-04 05:33:33
【问题描述】:
给定一个指向文件的 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
【问题讨论】:
-
如果您要投反对票,请留言说明原因。谢谢
-
我相信
filesize()不适用于 HTTP。你应该改用file_get_contents()。