當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CRM_Core_Form::setMaxFileSize方法代碼示例

本文整理匯總了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'));
 }
開發者ID:nganivet,項目名稱:civicrm-core,代碼行數:24,代碼來源:CSV.php

示例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}");
     }
 }
開發者ID:saurabhbatra96,項目名稱:civicrm-core,代碼行數:50,代碼來源:File.php


注:本文中的CRM_Core_Form::setMaxFileSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。