Böyle bir dosya ya da dizin yok: HTTP ile file_get_contents

3 Cevap php

I'm trying to execute a straightforward PHP call to load the contents of a web page: $result = file_get_contents("http://www.google.com");

The result coming back is a strange file not found error: Warning: file_get_contents(http://www.google.com): failed to open stream: No such file or directory in /var/www/html/test.php on line 5

Ben benim php.ini ve dizinde ayarı değiştirebilir yok. Htaccess dosyaları "On allow_url_fopen =" var. Herhangi bir fikir? Ben daha önce farklı sunucularda bu fonksiyon ile sorun vardı hiç.

3 Cevap

Görünüşe HTTP akışı sarıcı bu hataya neden olan, mevcut değildir.

print_r(stream_get_wrappers());

Array
(
    [0] => php
    [1] => file
    [2] => data
    [3] => compress.zlib
)

Ben kaldırıldı ya da nasıl geri nasıl emin değilim, ama bunu açıklamak istiyorum! Ben bir şekilde kayıtdışı olduğu durumda stream_wrapper_restore ('http') denedim, ama hiçbir etkisi yoktur.

Eğer "allow_url_fopen" değiştirerek üzerinde web sunucusu yeniden başlatmak mı?

VEYA

Kullanıcı aracısı "PHP" sorguladığınız sunucuda izin vermemesi olabilir.

VEYA

PHP Manual sayfasından: Not: Boşluklar gibi özel karakterler içeren bir URI açıyorsanız, urlencode ile URI () kodlamak gerekir.

Böyle php.ini ayarları bir test yapabilirsiniz ...

if (ini_get('allow_url_fopen') == '1') {
   // use fopen() or file_get_contents()
} else {
   // use curl or your custom function
}

Emin değilim, ama deneyin:

if(($fp=fopen('http://www.google.com/', 'rb'))!=null)
{
 // for php5 and up or use fread for php4
 $contents = stream_get_contents($fp);
 fclose($fp);
}