|
[PHP Code]
1. Using CURL (PHP 4 >= 4.0.2, PHP 5)
$service_url = "http://services.boldsystems.org/eFetch.php?id_type=sequenceid&ids=(1)&record_type=full&return_type=xml";
$contents = getContentsFromUrl($service_url);
if ($contents){
echo $contents;
}
function getContentsFromUrl($url){
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); //to follow the redeirects
$result = curl_exec($c);
curl_close($c);
return $result;
}
|
|
2. Using File methods (PHP 4 >= 4.0.2, PHP 5)
$service_url = "http://services.boldsystems.org/eFetch.php?id_type=sequenceid&ids=(1)&record_type=full&return_type=xml&file_type=zip";
$contents = getContentsFromUrl($service_url);
if ($contents){
writeFile($path,$contents);
}
function getContentsFromUrl($url){
$content = file_get_contents($url);
if ($content != false)
return $content;
else if (!isset($http_response_header))
return null; // Bad url, timeout
}
function writeFile($file,$datastr) {
$handle=fopen($file,'w');
$ret=fwrite($handle,$datastr."\n");
fclose($handle);
if (!$ret) return false;
else return true;
}
|