|
- public function download($url)
- {
- try {
- if(startsWith($url,'//')) $url = 'https:'.$url;
- $file_path = DIR_ROOT . 'image/files/';
- $key = md5(time().mt_rand(1000,9999)).'.pdf';
- $full_path = $file_path . $key;
- if(!is_file($full_path)){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $h = array('User-Agent:Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
- 'HTTP_ACCEPT:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
- curl_setopt($ch, CURLOPT_HTTPHEADER, $h);
- $rawdata = curl_exec($ch);
- curl_close($ch);
- $fp = fopen($full_path, 'w');
- fwrite($fp, $rawdata);
- fclose($fp);
- $this->uploadToBudget($full_path,$key);
- return $key;
- }
- return false;
- } catch (\Exception $exception) {
- echo $exception->getMessage();
- return false;
- }
- }
复制代码
|
|