I am trying to get the size from an remote image with the native php function getimagesize from an absolute URL.
I am using PHP 7.3, here is the code:
$fichier = 'http://mydomain/images/image.jpg';
$size = getimagesize($fichier);
var_dump($size);
And the code return :
PHP Warning: getimagesize(http://mydomain/images/image.jpg): failed to open stream: Connection refused in ...
And with fopen, same problem:
PHP Warning: fopen(http://mydomain/images/image.jpg): failed to open stream: Connection refused
And when I am trying the same URL from an other server, it is working.
Also, if I am trying to get infos from an other image and from an other domain but on the same server, it is not working also.
allow_url_fopen is enabled.
I think that it should come from Apache conf, but not sure... Anybody has an idea ?
Thanks !
Finally, the problem is coming from the network.
Apache could not resolve his own public domain name.
So to correct the problem, I just had " 127.0.0.1 mydomain" in the hosts file, and the problem was solved.
Hope it can help !
Related
I run a shopping site and am trying to save a copy of this remote gif image to my server as jpg.
$i='http://www.medexsupply.com/images/RO1R910C.GIF';
$imagejpg = imagecreatefromgif($i);
and it gives following errors :
Warning: imagecreatefromgif(): Couldn't resolve host name in /home/xxxxx/public_html/xxxxxxx/file.php on line 46
Warning: imagecreatefromgif(http://www.medexsupply.com/images/RO1R910C.GIF): failed to open stream: operation failed in /home/xxxxx/public_html/xxxxxxx/file.php on line 46
on line 46, the code is
$imagejpg = imagecreatefromgif($i);
I have dedicated server with 128MB memory limit for php scripts.
allow_url_fopen is on.
I can modify any setting on my server.
I could copy thousands of other remote images but not this image and images from some other sites.
Can someone help.
Please reply if you would like to know more information.
Thank you
There is a DNS issue with your domain, which explains the "could not resolve host" message.
From my browser, I can access your images. Yet from a different machine, I get:
$ dig www.medexsupply.com
; <<>> DiG 9.7.3 <<>> www.medexsupply.com
;; global options: +cmd
;; connection timed out; no servers could be reached
At this point in time, it could be possible that Sandy is the cause, as I see you are hosted with Rackspace in New York and, from the machine that gave the error above, I cannot ping their nameservers.
A URL can be used as a filename with this function "imagecreatefromgif " if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and List of Supported Protocols/Wrappers for a list of supported URL protocols.
I'm running a php site on localhost and i'm getting the following error.
Warning: file_get_contents(http://www.engadget.com/rss.xml)
[function.file-get-contents]: failed to open stream: HTTP request
failed! in C:\Program Files\xampp\htdocs\infohut\rss_read_class.php on
line 26
but when i run the same hosted in a real server, it doesn't give any error.
Also note that my local pc is connecting through a proxy and when i tried from a different pc with a direct connection to internet, the problem is not there.
So my guess is it has something to do with the proxy.
I'm using xampp for windows installation with php 5.1.4 and Apache 2.2.2
I tried adding my proxy settings to php.ini as well using below
pfpro.proxyaddress
pfpro.proxyport
still couldn't figure is out. Please advise if i need to change any other settings or anything.
Thanks
You should enable allow_url_fopen in your php.ini
When using file_get_contents() to get the file contents of a text file on an FTP server at ftp://ipaddress/somefile.txt, I'm getting the following error:
Warning: file_get_contents() [function.file-get-contents]: connect() failed: Permission denied in filename.php on line 1
But when I access ftp://ipaddress/somefile.txt within my webbrowser, it's absolutely no problem.
Why can my browser open the text file, but can file_get_contents() not?
PS: I don't know if it has something to do with it, but the ini directive allow_url_fopen is on.
I had a similar problem. Turns out it was a problem with SELinux on my server:
I ran this line from the terminal to reslove it:
setsebool -P httpd_can_network_connect on
Can you try to use readfile function like this and see if this gets the file contents:
readfile('ftp://anonymous:email#example.com#' . $ipAddress . '/somefile.txt');
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.
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.