你如何用cURL显示文件?

时间:2010-05-13 01:17:26

标签: php curl

像我这样的初学者,互联网上缺乏PHP cURL爱情。我想知道如何使用cURL下载&在我的PHP代码中显示一个ICS文件(它们对我来说是纯文本...)。除非fopen()容易1000倍,否则我想坚持使用cURL。

2 个答案:

答案 0 :(得分:3)

如果您的网络服务器允许,file_get_contents()就更容易了。

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

如果您无法使用file_get_contents()打开网址,请查看Stack Overflow上的所有内容,我认为这对初学者来说应该没问题。

答案 1 :(得分:0)

如果未启用远程file_get_contents,则cURL确实可以执行此操作。

$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);