Knowledgebase
Knowledgebase: PHP, ASP & CGI/Perl
How can I access remote files in PHP?
Posted by Diego Cousinet on 28 February 2011 08:36 AM

To download and include remote files within PHP you will need to use PHP's curl library, the full documentation for this can be found at the Client URL Functions reference page.

This is an example function you may wish to implement in your code as a replacement for the built in remote file includes, which are disabled for security reasons:

function remote_file($f){
$cr = curl_init($f);
curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($cr, CURLOPT_RETURNTRANSFER, TRUE);
$curl_ret = curl_exec($cr);
curl_close($cr);

return explode("\n",$curl_ret);
}

You would invoke this function by passing it a URL, for example print_r(remote_file("http://www.webdrive.co.nz"));

(26 vote(s))
Helpful
Not helpful

Comments (0)