Hello, I have this file_get_contents("http://www.intend.ro/images/produse/48999.jpg"). It give me: file_get_contents(http://www.intend.ro/images/produse/48999.jpg) [function.file-get-contents]: failed to open stream: Permission denied. I have tried with an image from another site and it worked. I don't really understand why is that happening.
The host has probably blocked file_get_contents with URLs because they don't want you stealing their images
The problem is I didn't find the directive or the way they were blocked by the admin. The person who built the site doesn't work there anymore and I have to tell to the new staff how to unblock them, so the problem is that I don't know what to tell them to do
Specifically the thing to look for should look something like this if it's in the php.ini file: disable_functions = file_get_contents ... or in a .htaccess file as: php_value disable_functions file_get_contents There may be more than just file_get_contents blocked too... which could mean that while @stats suggestion is a good one, that may be blocked as well. Generally speaking if such a block is in place it was done for security reasons, such as the codebase being outdated or failing to validate user-side input properly. A code audit may be in order to make sure that re-enabling that doesn't open your site up to being raped by every two bit cracker and script-kiddie out there.
I'm surprised that file_get_contents can open an URI Never saw that before. I would use PHP implementation of curl, it is build for this.
I don't get something right, maybe I didn't described the problem too good. I am using file_get_contents() from my domain, which is on server X, to download a photo from their domain, which is on server Y. If they have this:"disable_functions = file_get_contents" set in their server's php.ini, doesn't it mean that they won't be able to use the function( from their Y server ) not me( from server X, trying to download something from their server )?
If it's someone else's domain you have no control over that you are trying to pull the file from, they probably have a hotlinking block in place to prevent you from doing just that! It's called content theft, and a LOT of sites go to extremes to try and stop it.
The thing is that they will change what I tell them, in order for this to work, but I don't know what to tell them.
You mis-understood. The issue is from your server, not theirs. Server X must be set to allow file_get_contents to URLs. What is confusing me is that you said that it works on other images but not that domain, I have tested it and it works fine on my local server. The only thing I can advise you try is adding headers to mimic actual user, not sure if that would help: // Create headers to mimic actual user: $headers = array (); $headers[] = 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0'; $headers[] = 'Accept-Encoding: gzip, deflate'; $headers[] = 'Accept-Language: en-US,en;q=0.5'; $headers[] = 'Referer: http://www.intend.ro'; // Organize them for context $opts = array( 'http' => array( 'method' => 'GET', 'header' => implode("\r\n", $headers) ) ); // Create a context stream $context = stream_context_create($opts); // Open the file using the HTTP headers set above $file = file_get_contents('http://www.intend.ro/images/produse/48999.jpg', false, $context); PHP:
I managed to get to the person who built the website and he said that only one domain is allowed access to download photos. I don't know how he did it, but I have run the script from that one domain and it worked. Thanks and sorry for wasting your time.