Beispiel #1
0
 private function setFile($file)
 {
     $fileDir = Yii::$app->controller->module->id . '/' . date('Ymd');
     $path = Yii::$app->params['uploadPath'] . Yii::$app->params['uploadDir'] . '/' . $fileDir;
     $errorCode = $file->error;
     if ($errorCode === UPLOAD_ERR_OK) {
         $type = exif_imagetype($file->tempName);
         if ($type) {
             $extension = image_type_to_extension($type);
             //                $src = $path . '.original' . $extension;
             $fileDir = Yii::$app->controller->module->id . '/' . date('Y/m/d/');
             $fileName = date('YmdHis') . '.original' . $extension;
             $folder = Yii::$app->params['uploadPath'] . '/' . Yii::$app->params['uploadDir'] . '/' . $fileDir;
             \app\components\FileHelper::createDirectory($folder);
             $src = $folder . $fileName;
             if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_JPEG || $type == IMAGETYPE_PNG) {
                 if (file_exists($src)) {
                     unlink($src);
                 }
                 $result = $file->saveAs($src);
                 if ($result) {
                     $this->src = $src;
                     $this->type = $type;
                     $this->extension = $extension;
                     $this->setDst($extension);
                 } else {
                     $this->msg = 'Failed to save file';
                 }
             } else {
                 $this->msg = 'Please upload image with the following types: JPG, PNG, GIF';
             }
         } else {
             $this->msg = 'Please upload image file';
         }
     } else {
         $this->msg = $this->codeToMessage($errorCode);
     }
 }
 /**
  * @param $url
  * @param null $limit
  * @param int $current
  */
 private function crawl($url, $limit = null, &$current = 0)
 {
     echo "call crawl\n";
     echo $current . "\n";
     echo $limit . "\n";
     if (isset($limit) && $limit < $current) {
         echo "limit is over\n";
         echo "save next:{$url}\n";
         FileHelper::writeText(Url::to(static::INSTAGRAM_NEXT_URL), $url, true);
         return 1;
     }
     $data = Instagram::httpGet($url);
     Instagram::savePosts($data);
     if (!isset($data->pagination) || !isset($data->pagination->next_url)) {
         echo "end page\n";
         return 0;
     }
     return $this->crawl($data->pagination->next_url, $limit, ++$current);
 }