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


PHP CFileHelper::getRandomFilename方法代码示例

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


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

示例1: _fetchThumbnail

 /**
  * This function will regenerate the thumbnail of videos
  * @param int $id
  * @param bool $returnThumb
  * @return bool
  */
 public function _fetchThumbnail($id = 0, $returnThumb = false)
 {
     if (!COwnerHelper::isRegisteredUser()) {
         return;
     }
     if (!$id) {
         return false;
     }
     $table = JTable::getInstance('Video', 'CTable');
     $table->load($id);
     $config = CFactory::getConfig();
     if ($table->type == 'file') {
         // We can only recreate the thumbnail for local video file only
         // it's not possible to process remote video file with ffmpeg
         if ($table->storage != 'file') {
             $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . 'FFmpeg cannot process remote video.');
             return false;
         }
         $videoLib = new CVideoLibrary();
         $videoFullPath = JPATH::clean(JPATH_ROOT . '/' . $table->path);
         if (!JFile::exists($videoFullPath)) {
             return false;
         }
         // Read duration
         $videoInfo = $videoLib->getVideoInfo($videoFullPath);
         if (!$videoInfo) {
             return false;
         } else {
             $videoFrame = CVideosHelper::formatDuration((int) ($videoInfo['duration']['sec'] / 2), 'HH:MM:SS');
             // Create thumbnail
             $oldThumb = $table->thumb;
             $thumbFolder = CVideoLibrary::getPath($table->creator, 'thumb');
             $thumbSize = CVideoLibrary::thumbSize();
             $thumbFilename = $videoLib->createVideoThumb($videoFullPath, $thumbFolder, $videoFrame, $thumbSize);
         }
         if (!$thumbFilename) {
             return false;
         }
     } else {
         if (!CRemoteHelper::curlExists()) {
             $this->setError(JText::_('COM_COMMUNITY_CURL_NOT_EXISTS'));
             return false;
         }
         $videoLib = new CVideoLibrary();
         $videoObj = $videoLib->getProvider($table->path);
         if ($videoObj == false) {
             $this->setError($videoLib->getError());
             return false;
         }
         if (!$videoObj->isValid()) {
             $this->setError($videoObj->getError());
             return false;
         }
         $remoteThumb = $videoObj->getThumbnail();
         $thumbData = CRemoteHelper::getContent($remoteThumb, true);
         if (empty($thumbData)) {
             $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $remoteThumb);
             return false;
         }
         // split the header and body
         list($headers, $body) = explode("\r\n\r\n", $thumbData, 2);
         preg_match('/Content-Type: image\\/(.*)/i', $headers, $matches);
         if (!empty($matches)) {
             $thumbPath = CVideoLibrary::getPath($table->creator, 'thumb');
             $thumbFileName = CFileHelper::getRandomFilename($thumbPath);
             $tmpThumbPath = $thumbPath . '/' . $thumbFileName;
             if (!JFile::write($tmpThumbPath, $body)) {
                 $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $thumbFileName);
                 return false;
             }
             // We'll remove the old or none working thumbnail after this
             $oldThumb = $table->thumb;
             // Get the image type first so we can determine what extensions to use
             $info = getimagesize($tmpThumbPath);
             $mime = image_type_to_mime_type($info[2]);
             $thumbExtension = CImageHelper::getExtension($mime);
             $thumbFilename = $thumbFileName . $thumbExtension;
             $thumbPath = $thumbPath . '/' . $thumbFilename;
             if (!JFile::move($tmpThumbPath, $thumbPath)) {
                 $this->setError(JText::_('WARNFS_ERR02') . ': ' . $thumbFileName);
                 return false;
             }
             // Resize the thumbnails
             //CImageHelper::resizeProportional( $thumbPath , $thumbPath , $mime , CVideoLibrary::thumbSize('width') , CVideoLibrary::thumbSize('height') );
             list($width, $height) = explode('x', $config->get('videosThumbSize'));
             CImageHelper::resizeAspectRatio($thumbPath, $thumbPath, $width, $height);
         } else {
             $this->setError(JText::_('COM_COMMUNITY_PHOTOS_IMAGE_NOT_PROVIDED_ERROR'));
             return false;
         }
     }
     // Update the DB with new thumbnail
     $thumb = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME . '/' . $table->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/' . $thumbFilename;
     $table->set('thumb', $thumb);
//.........这里部分代码省略.........
开发者ID:joshjim27,项目名称:jobsglobal,代码行数:101,代码来源:videos.php

示例2: createVideoThumbFromRemote

 public function createVideoThumbFromRemote(&$videoObj)
 {
     $thumbData = CRemoteHelper::getContent($video->thumb);
     if ($thumbData) {
         jimport('joomla.filesystem.file');
         $thumbPath = CVideos::getPath($table->creator, 'thumb');
         $thumbFileName = CFileHelper::getRandomFilename($thumbPath);
         $tmpThumbPath = $thumbPath . '/' . $thumbFileName;
         if (JFile::write($tmpThumbPath, $thumbData)) {
             // Get the image type first so we can determine what extensions to use
             $info = getimagesize($tmpThumbPath);
             $mime = image_type_to_mime_type($info[2]);
             $thumbExtension = CImageHelper::getExtension($mime);
             $thumbFilename = $thumbFileName . $thumbExtension;
             $thumbPath = $thumbPath . '/' . $thumbFilename;
             JFile::move($tmpThumbPath, $thumbPath);
             // Resize the thumbnails
             //CFactory::load( 'libraries', 'videos' );
             CImageHelper::resizeProportional($thumbPath, $thumbPath, $mime, CVideos::thumbSize('width'), CVideo::thumbSize('height'));
             // Save
             $config = CFactory::getConfig();
             $thumb = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME . '/' . $table->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/' . $thumbFilename;
             $table->set('thumb', $thumb);
             $table->store();
         }
     }
 }
开发者ID:joshjim27,项目名称:jobsglobal,代码行数:27,代码来源:videos.php

示例3: cGenRandomFilename

/**
 * Deprecated since 1.8.x
 * Use CFileHelper::getRandomFilename instead
 **/
function cGenRandomFilename($directory, $filename = '', $extension = '', $length = 11)
{
    return CFileHelper::getRandomFilename($directory, $filename, $extension, $length);
}
开发者ID:joshjim27,项目名称:jobsglobal,代码行数:8,代码来源:file.php

示例4: upload

 public function upload()
 {
     $document = JFactory::getDocument();
     $mainframe = JFactory::getApplication();
     $my = $this->plugin->get('user');
     $creatorType = JRequest::getVar('creatortype', VIDEO_USER_TYPE);
     $groupid = $creatorType == VIDEO_GROUP_TYPE ? JRequest::getInt('groupid', 0) : 0;
     $config = CFactory::getConfig();
     CFactory::load('helpers', 'videos');
     CFactory::load('libraries', 'videos');
     $redirect = CVideosHelper::getVideoReturnUrlFromRequest();
     // Process according to video creator type
     if (!empty($groupid)) {
         CFactory::load('helpers', 'group');
         $allowManageVideos = CGroupHelper::allowManageVideo($groupid);
         $creatorType = VIDEO_GROUP_TYPE;
         $videoLimit = $config->get('groupvideouploadlimit');
         CError::assert($allowManageVideos, '', '!empty', __FILE__, __LINE__);
     } else {
         $creatorType = VIDEO_USER_TYPE;
         $videoLimit = $config->get('videouploadlimit');
     }
     // Check is video upload is permitted
     CFactory::load('helpers', 'limits');
     if (CLimitsHelper::exceededVideoUpload($my->id, $creatorType)) {
         $message = JText::sprintf('CC VIDEOS CREATION REACH LIMIT', $videoLimit);
         $this->setError($message);
         return false;
     }
     if (!$config->get('enablevideos')) {
         $this->setError(JText::_('CC VIDEO DISABLED', 'notice'));
         return false;
     }
     if (!$config->get('enablevideosupload')) {
         $this->setError(JText::_('CC VIDEO UPLOAD DISABLED', 'notice'));
         return false;
     }
     // Check if the video file is valid
     $files = JRequest::get('files');
     $videoFile = !empty($files['video']) ? $files['video'] : array();
     if (empty($files) || empty($videoFile['name']) && $videoFile['size'] < 1) {
         $this->setError(JText::_('CC VIDEO UPLOAD ERROR', 'error'));
         return false;
     }
     // Check file type.
     $fileType = $videoFile['type'];
     // Override from iphone
     $fileType = 'video/quicktime';
     $allowable = CVideosHelper::getValidMIMEType();
     if (!in_array($fileType, $allowable)) {
         $this->setError(JText::sprintf('CC VIDEO FILE TYPE NOT SUPPORTED', $fileType));
         return false;
     }
     // Check if the video file exceeds file size limit
     $uploadLimit = $config->get('maxvideouploadsize') * 1024 * 1024;
     $videoFileSize = sprintf("%u", filesize($videoFile['tmp_name']));
     if ($uploadLimit > 0 && $videoFileSize > $uploadLimit) {
         $this->setError(JText::sprintf('CC VIDEO FILE SIZE EXCEEDED', $uploadLimit));
         return false;
     }
     // Passed all checking, attempt to save the video file
     CFactory::load('helpers', 'file');
     $folderPath = CVideoLibrary::getPath($my->id, 'original');
     $randomFileName = CFileHelper::getRandomFilename($folderPath, $videoFile['name'], '');
     $destination = JPATH::clean($folderPath . DS . $randomFileName);
     if (!CFileHelper::upload($videoFile, $destination)) {
         $this->setError(JText::_('CC VIDEO UPLOAD FAILED', 'error'));
         return false;
     }
     $config = CFactory::getConfig();
     $videofolder = $config->get('videofolder');
     CFactory::load('models', 'videos');
     $video = JTable::getInstance('Video', 'CTable');
     $video->set('path', $videofolder . '/originalvideos/' . $my->id . '/' . $randomFileName);
     $video->set('title', JRequest::getVar('title'));
     $video->set('description', JRequest::getVar('description'));
     $video->set('category_id', JRequest::getInt('category', 0, 'post'));
     $video->set('permissions', JRequest::getInt('privacy', 0, 'post'));
     $video->set('creator', $my->id);
     $video->set('creator_type', $creatorType);
     $video->set('groupid', $groupid);
     $video->set('filesize', $videoFileSize);
     if (!$video->store()) {
         $this->setError(JText::_('CC VIDEO SAVE ERROR', 'error'));
         return false;
     }
     // Trigger for onVideoCreate
     $this->_triggerEvent('onVideoCreate', $video);
     // Video saved, redirect
     return $video;
 }
开发者ID:bizanto,项目名称:Hooked,代码行数:91,代码来源:videos.php


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