当前位置: 首页>>代码示例>>PHP>>正文


PHP Video::getMimeType方法代码示例

本文整理汇总了PHP中Video::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP Video::getMimeType方法的具体用法?PHP Video::getMimeType怎么用?PHP Video::getMimeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Video的用法示例。


在下文中一共展示了Video::getMimeType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add

 public function add($files, $albumID, $description = '', $tags = '')
 {
     # Check dependencies
     self::dependencies(isset($this->database));
     # Check permissions
     if (hasPermissions(LYCHEE_UPLOADS) === false || hasPermissions(LYCHEE_UPLOADS_BIG) === false || hasPermissions(LYCHEE_UPLOADS_THUMB) === false) {
         Log::error($this->database, __METHOD__, __LINE__, 'An upload-folder is missing or not readable and writable');
         exit('Error: An upload-folder is missing or not readable and writable!');
     }
     # Call plugins
     $this->plugins(__METHOD__, 0, func_get_args());
     switch ($albumID) {
         case 's':
             # s for public (share)
             $public = 1;
             $star = 0;
             $albumID = 0;
             break;
         case 'f':
             # f for starred (fav)
             $star = 1;
             $public = 0;
             $albumID = 0;
             break;
         case 'r':
             # r for recent
             $public = 0;
             $star = 0;
             $albumID = 0;
             break;
         default:
             $star = 0;
             $public = 0;
             break;
     }
     foreach ($files as $file) {
         # Verify file and set extension
         $mime_type = Video::getMimeType($file['tmp_name']);
         if ($mime_type === false) {
             Log::error($this->database, __METHOD__, __LINE__, 'Video format not supported');
             exit('Error: Video format  not supported!');
         }
         $extension = self::$allowedMimeTypes[$mime_type];
         # Generate id
         $id = str_replace('.', '', microtime(true));
         while (strlen($id) < 14) {
             $id .= 0;
         }
         # Set paths
         $tmp_name = $file['tmp_name'];
         $video_name = md5($id) . $extension;
         $path = LYCHEE_UPLOADS_VIDEO . $video_name;
         $path_thumb = "";
         # Create checksum based on $mime_type and $tmp_name
         $checksum = sha1_file($tmp_name);
         if ($checksum === false) {
             Log::error($this->database, __METHOD__, __LINE__, 'Could not calculate checksum for video');
             exit('Error: Could not calculate checksum for video!');
         }
         $exists = $this->exists($checksum);
         if ($exists !== false) {
             $video_name = $exists['video_name'];
             $path = $exists['path'];
             $path_thumb = $exists['path_thumb'];
             $exists = true;
         }
         if ($exists === false) {
             # Import if not uploaded via web
             if (!is_uploaded_file($tmp_name)) {
                 if (!@rename($tmp_name, $path)) {
                     Log::error($this->database, __METHOD__, __LINE__, 'Could not move video to uploads');
                     exit('Error: Could not move video to uploads!');
                 }
             } else {
                 if (!@move_uploaded_file($tmp_name, $path)) {
                     Log::error($this->database, __METHOD__, __LINE__, 'Could not move video to uploads');
                     exit('Error: Could not move video to uploads!');
                 }
             }
         }
         $info = array();
         #Read file info
         $info = $this->getInfo($path);
         $info['type'] = $mime_type;
         # Use title of file
         $info['title'] = substr(basename($file['name'], $extension), 0, 30);
         # Size
         $size = filesize($path) / 1024;
         if ($size >= 1024) {
             $info['size'] = round($size / 1024, 1) . ' MB';
         } else {
             $info['size'] = round($size, 1) . ' KB';
         }
         if ($exists === false) {
             #Create thumb
             if (!$this->createThumb($path, $video_name, $info['type'], $info['width'], $info['height'])) {
                 Log::error($this->database, __METHOD__, __LINE__, "Could not create thumbnail for video");
                 exit("Error:Could not create thumbnail for video");
             }
             #Set the thumbnail url
//.........这里部分代码省略.........
开发者ID:thejandroman,项目名称:Lychee,代码行数:101,代码来源:Video.php

示例2: server

 static function server($albumID = 0, $path)
 {
     global $database, $plugins, $settings;
     # Parse path
     if (!isset($path)) {
         $path = LYCHEE_UPLOADS_IMPORT;
     }
     if (substr($path, -1) === '/') {
         $path = substr($path, 0, -1);
     }
     if (is_dir($path) === false) {
         Log::error($database, __METHOD__, __LINE__, 'Given path is not a directory (' . $path . ')');
         return 'Error: Given path is not a directory!';
     }
     # Skip folders of Lychee
     if ($path === LYCHEE_UPLOADS_BIG || $path . '/' === LYCHEE_UPLOADS_BIG || $path === LYCHEE_UPLOADS_MEDIUM || $path . '/' === LYCHEE_UPLOADS_MEDIUM || $path === LYCHEE_UPLOADS_THUMB || $path . '/' === LYCHEE_UPLOADS_THUMB) {
         Log::error($database, __METHOD__, __LINE__, 'The given path is a reserved path of Lychee (' . $path . ')');
         return 'Error: Given path is a reserved path of Lychee!';
     }
     $error = false;
     $contains['photos'] = false;
     $contains['albums'] = false;
     # Invoke plugins directly, as instance method not valid here
     # Note that updated albumId and path explicitly passed, rather
     # than using func_get_args() which will only return original ones
     $plugins->activate(__METHOD__ . ":before", array($albumID, $path));
     # Get all files
     $files = glob($path . '/*');
     foreach ($files as $file) {
         # It is possible to move a file because of directory permissions but
         # the file may still be unreadable by the user
         if (!is_readable($file)) {
             $error = true;
             Log::error($database, __METHOD__, __LINE__, 'Could not read file or directory: ' . $file);
             continue;
         }
         if (@exif_imagetype($file) !== false) {
             # Photo
             if (!Import::photo($database, $plugins, $settings, $file, $albumID)) {
                 $error = true;
                 Log::error($database, __METHOD__, __LINE__, 'Could not import file: ' . $file);
                 continue;
             }
             $contains['photos'] = true;
         } else {
             if (Video::getMimeType($file) !== false) {
                 # Video
                 if (!Import::video($database, $plugins, $settings, $file, $albumID)) {
                     $error = true;
                     Log::error($database, __METHOD__, __LINE__, 'Could not import file: ' . $file);
                     continue;
                 }
                 $contains['videos'] = true;
             } else {
                 if (is_dir($file)) {
                     # Folder
                     $name = mysqli_real_escape_string($database, basename($file));
                     $album = new Album($database, null, null, null);
                     $newAlbumID = $album->add('[Import] ' . $name);
                     $contains['albums'] = true;
                     if ($newAlbumID === false) {
                         $error = true;
                         Log::error($database, __METHOD__, __LINE__, 'Could not create album in Lychee (' . $newAlbumID . ')');
                         continue;
                     }
                     $import = Import::server($newAlbumID, $file . '/');
                     if ($import !== true && $import !== 'Notice: Import only contains albums!') {
                         $error = true;
                         Log::error($database, __METHOD__, __LINE__, 'Could not import folder. Function returned warning');
                         continue;
                     }
                 }
             }
         }
     }
     # Invoke plugins directly, as instance method not valid here
     # Note that updated albumId and path explicitly passed, rather
     # than using func_get_args() which will only return original ones
     $plugins->activate(__METHOD__ . ":after", array($albumID, $path));
     if ($contains['photos'] === false && $contains['videos'] === false && $contains['albums'] === false) {
         return 'Warning: Folder empty or no readable files to process!';
     }
     if ($contains['photos'] === false && $contains['albums'] === true) {
         return 'Notice: Import only contains albums!';
     }
     return true;
 }
开发者ID:thejandroman,项目名称:Lychee,代码行数:87,代码来源:Import.php


注:本文中的Video::getMimeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。