本文整理匯總了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;
}
}