我搜索了幾個與此類似的帖子,但找不到答案。我可能錯過了一些小東西。file_get_contents()無法獲取數據?
我想如我的代碼從URL中讀取JSON內容:
$uri = "http://worldweatheronline.com/feed/weather.ashx?q=schruns,austria&format=json&num_of_days=5&key=8f2d1ea151085304102710";
echo "URI: [$uri] <br/>";
$file = file_get_contents($uri);
$error = error_get_last();
echo $error['message'];
如果我在瀏覽器中打開URL,我可以看到它的JSON內容。但上面提到的代碼不起作用。 $file
的值爲false
。錯誤消息是: file_get_contents(http://worldweatheronline.com/feed/weather.ashx?q=schruns,austria&format=json&num_of_days=5&key=8f2d1ea151085304102710) [function.file-get-contents]: failed to open stream: No such file or directory.
有什麼建議嗎?注意:如果它很重要,我的allow_url_fopen
設置爲1
。
編輯: 這是整個PHP文件。 http://pastebin.com/zCKEP9kG
另外,在打開一個http文件的代碼中有一個fopen()就好了。
你確定'allow_url_fopen'設置爲'1'嗎?如果你自己設置它,你可能需要重新啓動你的web服務器(假設PHP在某個服務器上運行)。 – Paulpro
@ ascii-lime:是的,我確定。我通過ini_get()來檢查它 – aakash