本文整理汇总了PHP中CRM_Core_Form::setMaxFileSize方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Form::setMaxFileSize方法的具体用法?PHP CRM_Core_Form::setMaxFileSize怎么用?PHP CRM_Core_Form::setMaxFileSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Form
的用法示例。
在下文中一共展示了CRM_Core_Form::setMaxFileSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildQuickForm
/**
* This is function is called by the form object to get the DataSource's
* form snippet. It should add all fields necesarry to get the data
* uploaded to the temporary table in the DB.
*
* @param CRM_Core_Form $form
*
* @return void
* (operates directly on form argument)
*/
public function buildQuickForm(&$form)
{
$form->add('hidden', 'hidden_dataSource', 'CRM_Import_DataSource_CSV');
$config = CRM_Core_Config::singleton();
$uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
$uploadSize = round($uploadFileSize / (1024 * 1024), 2);
$form->assign('uploadSize', $uploadSize);
$form->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
$form->setMaxFileSize($uploadFileSize);
$form->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
$form->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
$form->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
$form->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
}
示例2: buildAttachment
/**
* @param CRM_Core_Form $form
* @param string $entityTable
* @param int $entityID
* @param null $numAttachments
* @param bool $ajaxDelete
*/
public static function buildAttachment(&$form, $entityTable, $entityID = NULL, $numAttachments = NULL, $ajaxDelete = FALSE)
{
if (!$numAttachments) {
$numAttachments = Civi::settings()->get('max_attachments');
}
// Assign maxAttachments count to template for help message
$form->assign('maxAttachments', $numAttachments);
$config = CRM_Core_Config::singleton();
// set default max file size as 2MB
$maxFileSize = $config->maxFileSize ? $config->maxFileSize : 2;
$currentAttachmentInfo = self::getEntityFile($entityTable, $entityID, TRUE);
$totalAttachments = 0;
if ($currentAttachmentInfo) {
$totalAttachments = count($currentAttachmentInfo);
$form->add('checkbox', 'is_delete_attachment', ts('Delete All Attachment(s)'));
$form->assign('currentAttachmentInfo', $currentAttachmentInfo);
} else {
$form->assign('currentAttachmentInfo', NULL);
}
if ($totalAttachments) {
if ($totalAttachments >= $numAttachments) {
$numAttachments = 0;
} else {
$numAttachments -= $totalAttachments;
}
}
$form->assign('numAttachments', $numAttachments);
CRM_Core_BAO_Tag::getTags('civicrm_file', $tags, NULL, ' ', TRUE);
// get tagset info
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_file');
// add attachments
for ($i = 1; $i <= $numAttachments; $i++) {
$form->addElement('file', "attachFile_{$i}", ts('Attach File'), 'size=30 maxlength=60');
$form->addUploadElement("attachFile_{$i}");
$form->setMaxFileSize($maxFileSize * 1024 * 1024);
$form->addRule("attachFile_{$i}", ts('File size should be less than %1 MByte(s)', array(1 => $maxFileSize)), 'maxfilesize', $maxFileSize * 1024 * 1024);
$form->addElement('text', "attachDesc_{$i}", NULL, array('size' => 40, 'maxlength' => 255, 'placeholder' => ts('Description')));
if (!empty($tags)) {
$form->add('select', "tag_{$i}", ts('Tags'), $tags, FALSE, array('id' => "tags_{$i}", 'multiple' => 'multiple', 'class' => 'huge crm-select2', 'placeholder' => ts('- none -')));
}
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_file', NULL, FALSE, TRUE, "file_taglist_{$i}");
}
}