Example #1
0
 public function getByFiletype($filetype)
 {
     if (!$this->get_fid()) {
         return NULL;
     }
     if (trim($filetype) == '') {
         return NULL;
     }
     if ($this->oid > 0) {
         return NULL;
     }
     //此文件不是原始上传文件
     $sql = "SELECT * FROM `fs_fileentry`\n\t\t\t\tWHERE `oid`=" . $this->fid . " AND `ext`='{$filetype}'";
     $this->connectDB();
     if ($row = self::$db->fetchFirst($sql)) {
         $newFileEntry = new FileEntry();
         $newFileEntry->setFields($row);
         return $newFileEntry;
     }
     return NULL;
 }
Example #2
0
 /**
  *
  * 创建新文件
  * @param FileDirectory $basedir
  * @param Uploader $uploader
  */
 public function makeFile(Uploader $uploader)
 {
     $filename = $uploader->getTitle();
     if ($file_name = $this->getFilename($filename)) {
         $filepath = $this->path . '/' . $file_name;
         preg_match("/\\.([a-zA-Z0-9]{2,4})\$/", $file_name, $match);
         $ext = $match[1] ? strtolower($match[1]) : '';
         $fileModel = new FileEntry($this->uid);
         if ($fileModel->findOne($filepath)) {
             $filepath = $fileModel->getRecoverPath();
             //获取新文件路径名
         }
         //视频截图
         $thumbID = intval($uploader->thumb_id);
         if (!$thumbID) {
             $thumbInstance = $uploader->getThumbInstance();
             if ($thumbInstance) {
                 //更正截图的方向
                 $fileinfo = $uploader->getInfo();
                 if ($fileinfo['orientation']) {
                     if ($fileinfo['orientation'] < 0) {
                         $angle = intval(360 + $fileinfo['orientation']);
                     } else {
                         $angle = intval($fileinfo['orientation']);
                     }
                     $imagine = new \Imagine\Imagick\Imagine();
                     $image = $imagine->open($thumbInstance->tmpfile);
                     $image->rotate($angle)->save($thumbInstance->tmpfile);
                 }
                 $photoModel = new Photo();
                 if ($photoModel->create($thumbInstance, array('ctrl_type' => 2))) {
                     $thumbID = $photoModel->get_pid();
                 }
             }
         }
         $meta = array('oid' => intval($uploader->oid), 'uid' => $this->uid, 'source' => $uploader->tmpfile, 'size' => $uploader->getLength(), 'mime' => $uploader->getMIME(), 'md5' => $uploader->getMD5(), 'ext' => $ext, 'cid' => $uploader->cid ? $uploader->cid : 0, 'ctrl_type' => $uploader->ctrl_type ? $uploader->ctrl_type : 0, 'thumb_id' => $thumbID, 'meta' => $uploader->getInfo());
         if ($fileModel->create($filepath, $this->get_fid(), $meta)) {
             $this->updateStat($fileModel->size, 1);
             return $fileModel;
         }
     }
     return FALSE;
 }