public function downfile($url) { $path = C('TEMP_PATH'); $name = md5($url) . '.jpg'; $path = $path . $name; Http::curlDownload($url, $path); $info['name'] = $name; $info['type'] = 'image/jpeg'; $info['tmp_name'] = $path; $info["error"] = 0; $data['temp_image'] = $info; $Picture = D('Picture'); $pic_driver = C('PICTURE_UPLOAD_DRIVER'); $info = $Picture->upload($data, C('VIDEO_PICTURE_UPLOAD'), C('PICTURE_UPLOAD_DRIVER'), C("UPLOAD_{$pic_driver}_CONFIG")); if ($info) { $return['status'] = 1; $return = array_merge($info, $return); } else { $return['status'] = 0; $return['info'] = $Picture->getError(); } if (file_exists($path)) { unlink($myfile); } return $return; }
public function download($field, $value, $watermark = '0', $ext = 'gif|jpg|jpeg|bmp|png', $absurl = '', $basehref = '') { $dir = date('Y-m-d/'); $upload_url = '/Uploads/'; $uploadpath = $upload_url . $dir; $uploaddir = './Uploads/' . $dir; $string = stripslashes($value); //判断是否需要下载 if (!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\\.({$ext}))\\2/i", $string, $matches)) { return $value; } //取出下载的图片 $remotefileurls = array(); foreach ($matches[3] as $matche) { //如果是本地图片, 则跳过 if (strpos($matche, '://') === false) { continue; } $remotefileurls[] = $matche; } unset($matches, $string); $remotefileurls = array_unique($remotefileurls); $oldpath = $newpath = array(); //开始下载 //import("Org.Net.Http"); foreach ($remotefileurls as $k => $file) { //判断是否是本地图片 if (strpos($file, '://') === false || strpos($file, $upload_url) !== false) { continue; } //获取文件扩展名 $filename = fileext($file); //$file_name = basename($file); $filename = $this->getname($filename); $newfile = $uploaddir . $filename; \Org\Net\Http::curlDownload($file, $newfile); //var_dump($newfile);exit; } //替换下载后的地址 }
public function digg() { mysql_query('set names utf-8'); $page_num = 1; $item = ($page_num - 1) * 20; $url_arr = getUrl("http://book.douban.com/tag/%E7%BC%96%E7%A8%8B?start={$item}&type=T"); $i = 0; $book = M('Book'); foreach ($url_arr as $url) { $page = new \Analyse_Url($url); $value = array('title' => $page->getTitle(), 'author' => $page->getZuoZhe(), 'translator' => $page->getYiZhe(), 'price' => $page->getSimpleInfo("定价"), 'publisher' => $page->getSimpleInfo("出版社"), 'publish_time' => $page->getSimpleInfo("出版年"), 'page_num' => $page->getSimpleInfo("页数"), 'zhuangzhen' => $page->getSimpleInfo("装帧"), 'isbn' => $page->getSimpleInfo("ISBN"), 'introduct' => $page->getIntro(), 'pic_name_big' => __ROOT__ . '/Public/img/lpic/' . $page->getSimpleInfo("ISBN") . '.jpg', 'pic_name_small' => __ROOT__ . '/Public/img/mpic/' . $page->getSimpleInfo("ISBN") . '.jpg'); $pic_url = $page->getPic(); $big_pic_url = preg_replace('/mpic/', 'lpic', $pic_url); \Org\Net\Http::curlDownload($pic_url, './Public/img/mpic/' . $page->getSimpleInfo("ISBN") . '.jpg'); \Org\Net\Http::curlDownload($big_pic_url, './Public/img/lpic/' . $page->getSimpleInfo("ISBN") . '.jpg'); $book->data($value)->add(); $i++; if ($i > 10) { break; } } }
public function searchFolder() { import("ORG.Net.Http"); $id = I('get.goalID'); $url = "http://jwzx.cqupt.edu.cn/fileAttach.php?id=" . $id; $http = new Http(); $html = file_get_contents($url); $last = $http_response_header[7]; $last = explode('.', $last); $site = $_SERVER["SERVER_NAME"]; $setPosition = "./Public/jwzxnews/" . $id . '.' . $last[1]; if (!file_exists($setPosition)) { $http->curlDownload($url, $setPosition); } $folder_name = explode('/', $_SERVER["SCRIPT_NAME"]); $setPosition = "http://" . $site . '/' . $folder_name[1] . "/Public/jwzxnews/" . $id . '.' . $last[1]; echo json_encode($setPosition); }
public function saveCoverImage($url) { try { $config = C('ARTICLE_COVER_UPLOAD'); $name = md5($url) . '.jpg'; $path = $this->getName($config['subName'], $name) . '/'; $this->_createFolder($config['rootPath'] . $path); $savepath = "./" . $config['rootPath'] . $path . $name; Http::curlDownload($url, $savepath); $info['tmp_name'] = $savepath; $info['savename'] = $name; $info['name'] = $name; $info['type'] = 'image/jpeg'; $info['size'] = 2048; $info['md5'] = md5_file($savepath); $info['ext'] = 'jpg'; $info['savepath'] = $path; $info['path'] = $config['rootPath'] . $path . $name; /* 调用文件上传组件上传文件 */ $Picture = D('DcCover'); $pic_driver = C('PICTURE_UPLOAD_DRIVER'); $return = $Picture->uploadOne($info, C('ARTICLE_COVER_UPLOAD'), C('PICTURE_UPLOAD_DRIVER'), C("UPLOAD_{$pic_driver}_CONFIG")); // TODO:上传到远程服务器 return $return['id']; } catch (Exception $e) { ob_end_flush(); echo $e->getMessage() . "<br/>"; flush(); return; } }