public function geturiByMD5($md5_arr, $self = FALSE) { $r = array(); if (!$md5_arr) { return $r; } if (!is_array($md5_arr)) { $md5_arr = array($md5_arr); } $md5_arr = array_map('strtolower', $md5_arr); //构建sql查询语句 $sql = "SELECT `fid`,`md5`,`path`,`mime`,`thumb_id` FROM `fs_fileentry` WHERE 0 "; foreach ($md5_arr as $md5) { $sql .= "OR (`md5`='{$md5}'" . ($self ? " AND `uid`=" . Core::getUserID() : "") . ") "; } $this->connectDB(); $query = self::$db->query($sql); $result = array(); while ($row = self::$db->fetchArray($query)) { $md5 = $row['md5']; $id = intval($row['fid']); $thumb_id = intval($row['thumb_id']); $result[$md5] = array('id' => $id, 'src' => $this->geturi($id), 'mime' => $row['mime'], 'name' => $row['name']); if ($thumb_id) { $photoModel = new Photo(); if ($photoModel->findOne($thumb_id)) { $result[$md5]['thumb']['id'] = $photoModel->get_pid(); $result[$md5]['thumb']['mime'] = $photoModel->mime; $imgurls = $photoModel->geturi($thumb_id, 130); $result[$md5]['thumb']['src'] = $imgurls[0]; } } } foreach ($md5_arr as $md5) { $r[] = $result[$md5] ? $result[$md5] : array('id' => 0, 'src' => ''); } return $r; }
/** * * 创建新文件 * @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; }