file_get_contents和curl_init()都是用于获取远程web信息的,前面那个函数在本博客的Flickr相册中用到。
不过在将相册移植到另外一个空间时候,报如下错误:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in
原因是空间不支持file_get_contents这个函数,不过可以用另外一个函数curl_init()替代,同样能实现该功能:
原来代码片段:
$rsp = file_get_contents($url); $rsp_obj = unserialize($rsp);$url = "/services/rest/?".implode('&', $encoded_params);
修改后代码片段:
$ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $rsp = curl_exec($ch); curl_close($ch); $rsp_obj = unserialize($rsp);$url = "/services/rest/?".implode('&', $encoded_params);
不过有时空间也不支持curl_init()函数,会报如下错误:
Fatal error: Call to undefined function curl_init() in
要是两个函数都不支持,那只好换地方了。