Read a remote file using CURL in PHP
Read a remote file using CURL – Edit content (add a revision)
`section(title:'Read a remote file using CURL') On some hosts the only way to read a remote file is using curl because they forbids PHP from reading non-local resources. In order to get past their limitation you need to use a small trick .. use the CURL library. To check if your server has CURL, see `tutorial(name:'How to check if a PHP extension is installed') and check if cURL support is enabled. The function needs to be called by providing the URL for the resource you need and it will retrieve the resource's content. Example of usage : `code(language:'php' version:'5.2') {` $content = getFile('http://codepax.com'); `} and the function itself : `code(language:'php' version:'5.2') {` function getFile($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $tmp = curl_exec($ch); curl_close($ch); if ($tmp != false){ return $tmp; } } `}
Save as new Revision
Syntax docs