NYCPHP Meetup

NYPHP.org

[nycphp-talk] ini_set and file_get_contents

Brent Baisley brenttech at gmail.com
Wed May 6 13:19:01 EDT 2009


You should file_get_contents to retrieve URLs, which is what you seem
to be trying to do. It doesn't handle failures (i.e. timeout,
redirects) very well at all. You should use curl if you need to
retrieve a remote file.
	$url = 'http://yourfile.com';
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	$result = curl_exec($ch);
	if ( $result===false ) {
		echo curl_errno($ch).' '.curl_error($ch);
	}
	curl_close($ch);

Obviously you would want to do something different in the event there
is an error. Hopefully curl is enabled on your hosting server.

Brent Baisley


On Wed, May 6, 2009 at 10:22 AM, Tom Melendez <tom at supertom.com> wrote:
> On Wed, May 6, 2009 at 7:13 AM, Leam Hall <leam at reuel.net> wrote:
>> I have a file_get_contents working on my laptop/dev box, but when I put it
>> on the hosting server it comes back with an error.
>>
>>        URL file-access is disabled in the server configuration
>>
>> My guess is that there's a way to ini_set this to allow it, but the closest
>> thing I found was allow_url_fopen which doesn't seem to work. Or I just
>> don't know how to use it.
>>
>> Any pointers to docs that will enlighten me?
>
> You probably want to do this in your php.ini file, if this is on your
> laptop.  I'm not sure if this particular setting can be changed via
> ini_set, you'll have to look.
>
> Check here for more info:
>
> http://us3.php.net/manual/en/configuration.changes.php
>
> Thanks,
>
> Tom
> http://www.liphp.org
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>



More information about the talk mailing list