封裝方法
public static function downloadfile($file_url, $path)
{
$basepath = '/uploaded/';
if ($path) {
$basepath = $basepath . $path . '/';
}
$basepath = $basepath . date('Ymd');
$dir_path = __DIR__ . '/..' . $basepath;
if (!is_dir($dir_path)) {
mkdir($dir_path, 0777, true);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
$file = curl_exec($ch);
curl_close($ch);
$filename = pathinfo($file_url, PATHINFO_BASENAME);
$resource = fopen($dir_path. '/'. $filename, 'a');
fwrite($resource, $file);
fclose($resource);
return $basepath . '/' . $filename;
}
self::downloadfile($bill_pic, 'qipa250_pic');