How do you display a file with cURL?

There is an epic shortage of PHP cURL love on the web for beginners like me. I was wondering how to use cURL to load and display an ICS file (they are plain text to me ...) in my PHP code. If fopen()

1000x easier, I would like to stick with cURL for this.

+2


a source to share


2 answers


If your web server allows it, it's file_get_contents()

even easier.

echo file_get_contents('http://www.example.com/path/to/your/file.ics');

      



If you can't open URLs with file_get_contents()

, check out all the stuff on Stack Overflow which I think should be good for newbies.

+3


a source


If remote is file_get_contents

not enabled, cURL can actually do this.



$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, 'http://example.com/file.ics');

// this is the key option - sets curl_exec to return the HTTP response
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$file_contents = curl_exec($curl);

      

0


a source







All Articles