$file = #fopen("http://ajax.htm","rb");
I am getting this error while using fopen
Warning: fopen(xyz.htm): failed to open stream: HTTP request failed!
in /home/user/public_html/aaa/ttt.php on line 8
what could be the reason behind this?
I am going to go out on a huge limb here and suggest the problem is the url, 'http://ajax.htm'.
from docs:
If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.
edit: ajax.htm is not a valid url.
$file = #fopen("ajax.htm","rb");
there is your problem i think
http://nl3.php.net/function.fopen
Related
I'm trying to write the content of a page on my server to a variable using file_get_contents:
$lnk = "https://www.example.com/test%20file.php";
$otpt = file_get_contents($lnk);
The full URL is needed because I need the PHP output of the page and not the PHP script itself.
When running the above code I get this warning: failed to open stream: HTTP request failed! No other information, e. g. HTML error code, is provided. allow_url_fopen is enabled on the server. error_reporting(E_ALL) doesn't show any more information. The only thing which seems mentionable to me is that the file_get_contents request takes much too long (up to 30 secs) for the ~57 KB file I'm currently testing on.
I checked the Reference - What does this error mean in PHP?, but to no avail. I really have no idea what this message means since any further specification by PHP is missing. Any help would be very much appreciated.
Thanks in advance!
I am using file_get_contents on my PHP and it throws some errors:
My code
#try to fetch from remote
$this->remotePath = "http://some-hostname.com/blah/blah.xml
$fileIn = #file_get_contents($this->remotePath);
The errors:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /virtual/path/to/file/outputFile.php on line 127
Warning: file_get_contents(https://some-host-name/data/inputFile.xml) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /virtual/path/to/file/outputFile.php on line 127
Any idea? It worked fine in my computer but stopped working when I ported it to the web server.
Your server must have the allow_url_fopen property set to true. Being on a free webhost explains it, as it's usually disabled to prevent abuse. If you paid for your hosting, get in contact with your host so they can enable it for you.
If changing that setting is not an option, then have a look at the cURL library.
It seems "allow_url_fopen" setting is false on your server and hence does not allow using URLs with file_get_contents().
Try using CURL instead that is a better and efficient way of communicating with other server.
I'm using the following code in PHP5 on *nix systems to call a remote URL (handover of 2 parameter to a remote system:
$fp = fopen($url, "r");
$contents = stream_get_contents($fp);
fclose($fp);
Unfortunately it fails for https (http works correctly) on Windows/IIS with the following error message (although allow_url_fopen is definitely enabled):
fopen(https://www.example.com/?method=abc&par=xyz) [function.fopen]: failed to open stream: No error in C:\Inetpub\wwwroot\libs\externalSys.php on line 122
Hence my questions:
Has anyone else found a solution?
Are there any alternatives? Curl
is unfortunately not
installed/available.
This looks like you may not have included the php_openssl.dll in your php.ini, so https fopens will fail. Does it work with just standard http?
You can try using file_get_contents.
Usage:
$contents = file_get_contents($url);
file_get_contents() is returning "failed to open stream" when I call it on an HTTPS URL.
Warning: file_get_contents(https://google.com) [function.file-get-contents]: failed to open stream: No error in E:\\htdocs\callback3.php on line 5
Same call will work with a non-SSL URL.
At first, I thought it was a security issue with my webhoster, but I have verified with phpinfo() that allow url open is indeed allowed. I have also tried this code and verified it works:
Anyone have any ideas why file_get_contents() is failing with an HTTPS URL?
update: People correctly pointed out this was an HTTPS issue. My webhoster claims this should work, and has no idea how to resolve this. Anyone have specific directions I can give them for their IIS7 setup?
That is probably because they are using the secure protocol https. This is strange though, in their examples, facebook is giving the similar example.
i got an error message when i try to do file_get_contents() function
Warning: file_get_contents()
[function.file-get-contents]: URL
file-access is disabled in the server
configuration in
/data/20/1/112/111/1927437/user/2100551/htdocs/cti-dev/admin/my
path
My site is https ..
how this happend? Does any one help me ?
This error is occurs when allow_url_fopen is disabled. You'll need to use cURL to grab this file or change your PHP.ini config.
Someone has disabled URL access in fopen() et alia, probably with allow_url_fopen.