本文整理汇总了PHP中CFileHelper::upload方法的典型用法代码示例。如果您正苦于以下问题:PHP CFileHelper::upload方法的具体用法?PHP CFileHelper::upload怎么用?PHP CFileHelper::upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFileHelper
的用法示例。
在下文中一共展示了CFileHelper::upload方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cUploadFile
/**
* Deprecated since 1.8.x
* Use CFileHelper::upload instead
**/
function cUploadFile($source, $destination)
{
return CFileHelper::upload($source, $destination);
}
示例2: upload
public function upload()
{
// Check for request forgeries
JRequest::checkToken() or jexit(JText::_('CC INVALID TOKEN'));
if ($this->blockUnregister()) {
return;
}
$this->checkVideoAccess();
$document = JFactory::getDocument();
$viewType = $document->getType();
$viewName = JRequest::getCmd('view', $this->getName());
$view = $this->getView($viewName, '', $viewType);
$mainframe = JFactory::getApplication();
$my = CFactory::getUser();
$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);
$mainframe->redirect($redirect, $message);
exit;
}
if (!$config->get('enablevideos')) {
$mainframe->enqueueMessage(JText::_('CC VIDEO DISABLED', 'notice'));
$mainframe->redirect(CRoute::_('index.php?option=com_community&view=frontpage', false));
exit;
}
if (!$config->get('enablevideosupload')) {
$mainframe->enqueueMessage(JText::_('CC VIDEO UPLOAD DISABLED', 'notice'));
$mainframe->redirect(CRoute::_('index.php?option=com_community&view=videos', false));
exit;
}
// Check if the video file is valid
$files = JRequest::get('files');
$videoFile = !empty($files['videoFile']) ? $files['videoFile'] : array();
if (empty($files) || empty($videoFile['name']) && $videoFile['size'] < 1) {
$mainframe->enqueueMessage(JText::_('CC VIDEO UPLOAD ERROR', 'error'));
$mainframe->redirect($redirect, false);
exit;
}
// Check file type.
$fileType = $videoFile['type'];
$allowable = CVideosHelper::getValidMIMEType();
if (!in_array($fileType, $allowable)) {
$mainframe->redirect($redirect, JText::sprintf('CC VIDEO FILE TYPE NOT SUPPORTED', $fileType));
exit;
}
// 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) {
$mainframe->redirect($redirect, JText::sprintf('CC VIDEO FILE SIZE EXCEEDED', $uploadLimit));
}
// 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)) {
$mainframe->enqueueMessage(JText::_('CC VIDEO UPLOAD FAILED', 'error'));
$mainframe->redirect($redirect, false);
exit;
}
$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()) {
$mainframe->enqueueMessage(JText::_('CC VIDEO SAVE ERROR', 'error'));
$mainframe->redirect($redirect, false);
exit;
}
// Trigger for onVideoCreate
$this->_triggerEvent('onVideoCreate', $video);
// Video saved, redirect
//.........这里部分代码省略.........
示例3: upload
public function upload()
{
// Check for request forgeries
JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN'));
if ($this->blockUnregister()) {
return;
}
$this->checkVideoAccess();
$document = JFactory::getDocument();
$viewType = $document->getType();
$viewName = JRequest::getCmd('view', $this->getName());
$view = $this->getView($viewName, '', $viewType);
$mainframe = JFactory::getApplication();
$jinput = $mainframe->input;
$my = CFactory::getUser();
$creatorType = $jinput->get('creatortype', VIDEO_USER_TYPE, 'NONE');
//JRequest::getVar('creatortype', VIDEO_USER_TYPE);
$groupid = $jinput->get('groupid', 0, 'INT');
$eventid = $jinput->get('eventid', 0, 'INT');
$config = CFactory::getConfig();
$redirect = CVideosHelper::getVideoReturnUrlFromRequest();
// @rule: Do not allow users to add more videos than they are allowed to
//CFactory::load( 'libraries' , 'limits' );
if (CLimitsLibrary::exceedDaily('videos')) {
$mainframe->redirect($redirect, JText::_('COM_COMMUNITY_VIDEOS_LIMIT_REACHED'), 'error');
}
// Process according to video creator type
list($creatorType, $videoLimit) = $this->_manipulateParameter($groupid, $eventid, $config);
$group = JTable::getInstance('Group', 'CTable');
$group->load($groupid);
if ($group->approvals) {
$permission = 40;
}
$permission = JRequest::getInt('permissions', 0, 'post');
// Check is video upload is permitted
if (CLimitsHelper::exceededVideoUpload($my->id, $creatorType)) {
$message = JText::sprintf('COM_COMMUNITY_VIDEOS_CREATION_LIMIT_ERROR', $videoLimit);
$mainframe->redirect($redirect, $message);
exit;
}
if (!$config->get('enablevideos')) {
$mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_VIDEO_DISABLED', 'notice'));
$mainframe->redirect(CRoute::_('index.php?option=com_community&view=frontpage', false));
exit;
}
if (!$config->get('enablevideosupload')) {
$mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_UPLOAD_DISABLED', 'notice'));
$mainframe->redirect(CRoute::_('index.php?option=com_community&view=videos', false));
exit;
}
// Check if the video file is valid
$files = JRequest::get('files');
$videoFile = !empty($files['videoFile']) ? $files['videoFile'] : array();
if (empty($files) || empty($videoFile['name']) && $videoFile['size'] < 1) {
$mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_UPLOAD_ERROR', 'error'));
$mainframe->redirect($redirect, false);
exit;
}
// Check file type.
$fileType = CVideosHelper::getMIMEType($videoFile);
$allowable = CVideosHelper::getValidMIMEType();
if (!in_array(strtolower($fileType), $allowable)) {
$mainframe->redirect($redirect, JText::sprintf('COM_COMMUNITY_VIDEOS_FILETYPE_ERROR', $fileType));
exit;
}
$fileExtension = pathinfo($videoFile['name']);
$allowextension = CVideosHelper::getValidExtensionType();
if (!in_array(strtolower($fileExtension['extension']), $allowextension)) {
$mainframe->redirect($redirect, JText::sprintf('COM_COMMUNITY_VIDEOS_FILETYPE_ERROR', $fileExtension['extension']));
exit;
}
// Check if the video file exceeds file size limit
$uploadLimit = $config->get('maxvideouploadsize');
/* MB unit */
$videoFileSize = sprintf("%u", filesize($videoFile['tmp_name']));
//convert to MB
$videoFileSize = number_format($videoFileSize / 1048576, 2);
if ($uploadLimit > 0 && $videoFileSize > $uploadLimit) {
$mainframe->redirect($redirect, JText::sprintf('COM_COMMUNITY_VIDEOS_FILE_SIZE_EXCEEDED', $uploadLimit));
}
// Passed all checking, attempt to save the video file
$folderPath = CVideoLibrary::getPath($my->id, 'original');
$randomFileName = CFileHelper::getRandomFilename($folderPath, $videoFile['name'], '');
$destination = JPATH::clean($folderPath . '/' . $randomFileName);
if (!CFileHelper::upload($videoFile, $destination)) {
$mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_UPLOAD_ERROR', 'error'));
$mainframe->redirect($redirect, false);
exit;
}
$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', $jinput->get('title', '', 'STRING'));
$video->set('description', $jinput->get('description', '', 'STRING'));
$video->set('category_id', JRequest::getInt('category_id', 0, 'post'));
$video->set('permissions', $permission);
$video->set('creator', $my->id);
$video->set('creator_type', $creatorType);
//.........这里部分代码省略.........
示例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;
}