本文整理汇总了PHP中TemplateHelper::canUpload方法的典型用法代码示例。如果您正苦于以下问题:PHP TemplateHelper::canUpload方法的具体用法?PHP TemplateHelper::canUpload怎么用?PHP TemplateHelper::canUpload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TemplateHelper
的用法示例。
在下文中一共展示了TemplateHelper::canUpload方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadFile
/**
* Upload new file.
*
* @param string $file The name of the file.
* @param string $location Location for the new file.
*
* @return boolean True if file uploaded successfully, false otherwise
*
* @since 3.2
*/
public function uploadFile($file, $location)
{
jimport('joomla.filesystem.folder');
if ($template = $this->getTemplate()) {
$app = JFactory::getApplication();
$client = JApplicationHelper::getClientInfo($template->client_id);
$path = JPath::clean($client->path . '/templates/' . $template->element . '/');
$fileName = JFile::makeSafe($file['name']);
$err = null;
JLoader::register('TemplateHelper', JPATH_COMPONENT_ADMINISTRATOR . '/helpers/template.php');
if (!TemplateHelper::canUpload($file, $err)) {
// Can't upload the file
return false;
}
if (file_exists(JPath::clean($path . '/' . $location . '/' . $file['name']))) {
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_EXISTS'), 'error');
return false;
}
if (!JFile::upload($file['tmp_name'], JPath::clean($path . '/' . $location . '/' . $fileName))) {
$app->enqueueMessage(JText::_('COM_TEMPLATES_FILE_UPLOAD_ERROR'), 'error');
return false;
}
$url = JPath::clean($location . '/' . $fileName);
return $url;
}
}