tags:

views:

57

answers:

2

There is an epic lack of PHP cURL love on the Internet for beginners like me. I was wondering how to use cURL to download & display an ICS file (They're plain text to me...) in my PHP code. Unless fopen() is 1,000 times easier, I'd like to stick with cURL for this one.

+3  A: 

If your webserver allows it, file_get_contents() is even easier.

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

If you can not open URLs with file_get_contents() check out all the stuff on Stack Overflow, which I believe should be fine for a beginner.

alex
COOL! "Allows it?" I'm on slicehost man, it allows anything I want it too!
Kyle
Just remember to add the proper `Content-Type` header before you echo the statement, otherwise you will just get plain text.
webdestroya
The entire point of the proxy was plain text actually. I needed to parse the ics with Javascript. I know it sounds crazy ;D
Kyle
A: 

If remote file_get_contents is not enabled, cURL can indeed 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);
ceejayoz