I could successfully connect to a web service, it provides a list of files that I need to save them on my disk, I am wondering how can I download and save them on my disk?
simple response is as following (response is shorten)
<files>
<file>
<name>1.jpeg</name>
<address>c:\photos\1.jpeg</address>
<url>www.xxx.com\photos\1.jpeg</url>
</file>
<file>
<name>my.pdf</name>
<address>c:\pdfs\my.pdf</address>
<url>www.xxx.com\pdfs\my.pdf</url>
</file>
</files>
I've found the following but not sure how to save the $output
function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
I used the following but something is wrong, it create the file but its empty
$fp = fopen("lib\1",'x');
fwrite($f, $output);
fclose($fp);