Exemple #1
0
 /**
  * 抓取远程图片
  * @return string
  */
 protected function actionCrawler()
 {
     /* 上传配置 */
     $config = array("pathFormat" => $this->config['catcherPathFormat'], "maxSize" => $this->config['catcherMaxSize'], "allowFiles" => $this->config['catcherAllowFiles'], "oriName" => "remote.png");
     $fieldName = $this->config['catcherFieldName'];
     /* 抓取远程图片 */
     $list = array();
     if (isset($_POST[$fieldName])) {
         $source = $_POST[$fieldName];
     } else {
         $source = $_GET[$fieldName];
     }
     foreach ($source as $imgUrl) {
         $item = new Uploader($imgUrl, $config, "remote");
         $info = $item->getFileInfo();
         array_push($list, array("state" => $info["state"], "url" => $info["url"], "size" => $info["size"], "title" => htmlspecialchars($info["title"]), "original" => htmlspecialchars($info["original"]), "source" => htmlspecialchars($imgUrl)));
     }
     /* 返回抓取数据 */
     return json_encode(array('state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list));
 }
Exemple #2
0
 /**
  * 抓取远程图片
  * @return string
  */
 protected function remoteSave()
 {
     /* 上传配置 */
     $config = ['pathFormat' => $this->config['catcherPathFormat'], 'maxSize' => $this->config['catcherMaxSize'], 'allowFiles' => $this->config['catcherAllowFiles'], 'oriName' => 'remote.png'];
     $fieldName = $this->config['catcherFieldName'];
     /* 抓取远程图片 */
     $list = [];
     if (Yii::$app->getRequest()->post($fieldName)) {
         $source = Yii::$app->getRequest()->post($fieldName);
     } else {
         $source = Yii::$app->getRequest()->get($fieldName);
     }
     foreach ($source as $imgUrl) {
         $uploader = new Uploader($imgUrl, $config, 'remote');
         $info = $uploader->getFileInfo();
         if ($info['state'] == 'SUCCESS') {
             array_push($list, ['state' => $info['state'], 'url' => $info['url'], 'size' => $info['size'], 'title' => htmlspecialchars($info['title']), 'original' => htmlspecialchars($info['original']), 'source' => htmlspecialchars($imgUrl)]);
         }
     }
     /* 返回抓取数据 */
     return Json::encode(['state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list]);
 }