<?php
function getContents($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
function downloadFile($url, $path, $file) {
//if (!file_exists($path)) mkdir($path, 0755, true);
$filePath = $path . ‘/’ . $file;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$fp = fopen($filePath, “wb”);
$options = array(
CURLOPT_URL => $url,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_FILE => $fp);
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}