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.
views:
57answers:
2
+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
2010-05-13 01:19:10
COOL! "Allows it?" I'm on slicehost man, it allows anything I want it too!
Kyle
2010-05-13 01:21:12
Just remember to add the proper `Content-Type` header before you echo the statement, otherwise you will just get plain text.
webdestroya
2010-05-13 01:26:44
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
2010-05-13 01:32:50
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
2010-05-13 02:42:40