Example #1
0
 /**
  * 根據文件Id获取文件数据
  */
 public function getLink($fileId, $linkType, $shareKey)
 {
     $data = array();
     $file = MiniFile::getInstance()->getById($fileId);
     $data["name"] = $file["file_name"];
     $data["bytes"] = intval($file["file_size"] + "");
     $fileType = $file["file_type"];
     if ($fileType == 0) {
         $data["icon"] = MiniHttp::getIcon4File($file["file_name"]);
         if (!MiniUtil::isMixCloudVersion()) {
             $data["icon"] = MiniHttp::getMiniHost() . "statics/static/mini-box/images/link/" . $data["icon"];
         } else {
             $data["icon"] = "http://static.miniyun.cn/static/mini-box/images/link/" . $data["icon"];
         }
     }
     $ext = MiniUtil::getFileExtension($file["file_name"]);
     $path = MiniUtil::getRelativePath($file["file_path"]);
     if ($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif") {
         $data["thumbnail_link"] = MiniHttp::createAnonymousUrl("linkAccess/thumbnail?key=" . $shareKey . "&size=256x256&path=" . urlencode($path));
     } else {
         $data["thumbnail_link"] = "";
     }
     if ($linkType == MiniLink::$PREVIEW_LINK) {
         $data["link"] = MiniHttp::createUrl("link/access/key/" . $shareKey);
     } else {
         $data["link"] = MiniHttp::createAnonymousUrl("linkAccess/download?key=" . $shareKey . "&path=" . urlencode($path));
     }
     return $data;
 }
Example #2
0
 /**
  * 根据文件名获得适配该文件名的icon地址
  * @param $fileName
  * @return string
  */
 public static function getIcon4File($fileName)
 {
     $iconName = "page_white.png";
     $ext = MiniUtil::getFileExtension($fileName);
     if (!empty($ext)) {
         $type = "page_white";
         if ($ext === "pdf") {
             $type = "page-white-acrobat";
         }
         if ($ext === "psd") {
             $type = "page-white-paint";
         }
         $mimeTypes = array("c", "c++", "m", "php", "java", "h", "py", "js", "css", "xml", "sql");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-code";
             }
         }
         $mimeTypes = array("zip", "rar", "7z", "gz");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-compressed";
             }
         }
         $mimeTypes = array("iso");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-dvd";
             }
         }
         $mimeTypes = array("xls", "xlsx");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-excel";
             }
         }
         $mimeTypes = array("mp4", "rm", "avi", "rmvb", "mov", "asf", "wmv", "3gp", "flv");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-film";
             }
         }
         $mimeTypes = array("exe", "dll");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-gear";
             }
         }
         $mimeTypes = array("jpg", "jpeg", "png", "bmp", "gif");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-picture";
             }
         }
         $mimeTypes = array("ppt", "pptx");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-powerpoint";
             }
         }
         $mimeTypes = array("mp3", "mid", "wav", "ape", "flac");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-sound";
             }
         }
         $mimeTypes = array("doc", "docx");
         foreach ($mimeTypes as $code) {
             if ($ext === $code) {
                 $type = "page-white-word";
             }
         }
         $iconName = $type . ".png";
     }
     return $iconName;
 }
Example #3
0
 /**
  * 创建外链
  */
 public function createLink($linkType, $password, $expiryTime)
 {
     $result = $this->valid();
     if ($result["success"] === false) {
         return $result;
     }
     $file = $this->file;
     //创建外链
     $link = MiniLink::getInstance()->create($this->user["id"], $file["id"], $password, $expiryTime);
     //创建外链属性
     MiniChooserLink::getInstance()->create($link["id"], $this->appKey, $this->session);
     //返回直链或预览链接
     $data = array();
     $data["success"] = true;
     $data["name"] = $file["file_name"];
     $data["bytes"] = intval($file["file_size"] + "");
     //获得文件的icon
     $fileType = $file["file_type"];
     //根据文件后缀,如果为jpg/jpeg/gif/png就直接显示缩略图
     $ext = MiniUtil::getFileExtension($file["file_name"]);
     if ($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif") {
         $data["thumbnail_link"] = MiniHttp::createUrl("link/thumbnail/key/" . $link["share_key"]);
     } else {
         $data["thumbnail_link"] = "";
     }
     if ($linkType == MiniLink::$PREVIEW_LINK) {
         $data["link"] = MiniHttp::createUrl("link/access/key/" . $link["share_key"]);
     } else {
         $data["link"] = MiniHttp::createUrl("link/direct/key/" . $link["share_key"]);
     }
     return $data;
 }