本文整理汇总了PHP中FileField类的典型用法代码示例。如果您正苦于以下问题:PHP FileField类的具体用法?PHP FileField怎么用?PHP FileField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setAttribute
/**
* Determine if it is a URL upload or file upload.
* Upload the file and set file name
*
* @param $key
* @param $value
*/
public function setAttribute($key, $value)
{
if (in_array($key, array_keys($this->fileFields)) && $value) {
// If valid URL and file exists, download it
if (filter_var($value, FILTER_VALIDATE_URL)) {
$headers = @get_headers($value);
if (strpos($headers[0], '200') || strpos($headers[0], '301') || strpos($headers[0], '302')) {
$fileName = pathinfo($value, PATHINFO_FILENAME);
$extension = pathinfo($value, PATHINFO_EXTENSION);
$fullFileName = join('.', [$fileName, $extension]);
$fileField = new FileField($this, $key, $fullFileName);
$this->attributes[$key] = $fileField->uploadRemoteFile($value);
}
} elseif ($value instanceof UploadedFile) {
$fileName = str_slug(pathinfo($value->getClientOriginalName(), PATHINFO_FILENAME));
$extension = $value->getClientOriginalExtension();
$fullFileName = join('.', [$fileName, $extension]);
$fileField = new FileField($this, $key, $fullFileName);
$this->attributes[$key] = $fileField->uploadFile($value);
} elseif (is_string($value)) {
$fileName = pathinfo($value, PATHINFO_FILENAME);
$extension = pathinfo($value, PATHINFO_EXTENSION);
$fullFileName = join('.', [$fileName, $extension]);
$fileField = new FileField($this, $key, $fullFileName);
$this->attributes[$key] = $fileField->copyLocal($value);
}
} else {
parent::setAttribute($key, $value);
}
}
示例2: __construct
public function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
{
if (!$fields) {
$helpHtml = _t('GroupImportForm.Help1', '<p>Import one or more groups in <em>CSV</em> format (comma-separated values).' . ' <small><a href="#" class="toggle-advanced">Show advanced usage</a></small></p>');
$helpHtml .= _t('GroupImportForm.Help2', '<div class="advanced">
<h4>Advanced usage</h4>
<ul>
<li>Allowed columns: <em>%s</em></li>
<li>Existing groups are matched by their unique <em>Code</em> value, and updated with any new values from the
imported file</li>
<li>Group hierarchies can be created by using a <em>ParentCode</em> column.</li>
<li>Permission codes can be assigned by the <em>PermissionCode</em> column. Existing permission codes are not
cleared.</li>
</ul>
</div>');
$importer = new GroupCsvBulkLoader();
$importSpec = $importer->getImportSpec();
$helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
$fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('CsvFile', _t('SecurityAdmin_MemberImportForm.FileFieldLabel', 'CSV File <small>(Allowed extensions: *.csv)</small>')));
$fileField->getValidator()->setAllowedExtensions(array('csv'));
}
if (!$actions) {
$action = new FormAction('doImport', _t('SecurityAdmin_MemberImportForm.BtnImport', 'Import from CSV'));
$action->addExtraClass('ss-ui-button');
$actions = new FieldList($action);
}
if (!$validator) {
$validator = new RequiredFields('CsvFile');
}
parent::__construct($controller, $name, $fields, $actions, $validator);
$this->addExtraClass('cms');
$this->addExtraClass('import-form');
}
示例3: __construct
public function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
{
if (!$fields) {
$helpHtml = _t('MemberImportForm.Help1', '<p>Import users in <em>CSV format</em> (comma-separated values).' . ' <small><a href="#" class="toggle-advanced">Show advanced usage</a></small></p>');
$helpHtml .= _t('MemberImportForm.Help2', '<div class="advanced">' . '<h4>Advanced usage</h4>' . '<ul>' . '<li>Allowed columns: <em>%s</em></li>' . '<li>Existing users are matched by their unique <em>Code</em> property, and updated with any new values from ' . 'the imported file.</li>' . '<li>Groups can be assigned by the <em>Groups</em> column. Groups are identified by their <em>Code</em> property, ' . 'multiple groups can be separated by comma. Existing group memberships are not cleared.</li>' . '</ul>' . '</div>');
$importer = new MemberCsvBulkLoader();
$importSpec = $importer->getImportSpec();
$helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
$fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('CsvFile', _t('SecurityAdmin_MemberImportForm.FileFieldLabel', 'CSV File <small>(Allowed extensions: *.csv)</small>')));
$fileField->getValidator()->setAllowedExtensions(array('csv'));
}
if (!$actions) {
$action = new FormAction('doImport', _t('SecurityAdmin_MemberImportForm.BtnImport', 'Import from CSV'));
$action->addExtraClass('ss-ui-button');
$actions = new FieldList($action);
}
if (!$validator) {
$validator = new RequiredFields('CsvFile');
}
parent::__construct($controller, $name, $fields, $actions, $validator);
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/MemberImportForm.js');
$this->addExtraClass('cms');
$this->addExtraClass('import-form');
}
示例4: getFormField
public function getFormField()
{
$field = new FileField($this->Name, $this->Title);
if ($this->getSetting('Folder')) {
$folder = Folder::get()->byId($this->getSetting('Folder'));
if ($folder) {
$field->setFolderName(preg_replace("/^assets\\//", "", $folder->Filename));
}
}
return $field;
}
示例5: CreateHeatmapForm
public function CreateHeatmapForm()
{
$includeWatermark = array("1" => "Yes,Include Watermark", "0" => "No,Remove Watermark");
$fields = new FieldList($imageField = new FileField('OriginalImage', 'Upload an Image File'), new LiteralField('UploadInfo', 'Acceptable images are jpg or png, 500-1600 pixels wide by 500-1200 pixels height.<hr>'), new OptionsetField('IncludeWatermark', 'Include Watermark?', $includeWatermark, 1));
$imageField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png'));
$imageField->setAttribute('class', 'jfilestyle');
$imageField->setAttribute('data-buttonText', "<img src='themes/attwiz/images/button-create-heatmap-browse.jpg'></img>");
$imageField->setAttribute('data-placeholder', 'No file selected..');
// Create action
$actions = new FieldList($submit = new FormAction('processCreateHeatmap', ''));
$submit->setAttribute('src', 'themes/attwiz/images/button-create-heatmap-blue-bg.jpg');
// Create action
$validator = new RequiredFields('OriginalImage', 'IncludeWatermark');
return new Form($this, 'CreateHeatmapForm', $fields, $actions, $validator);
}
示例6: __construct
public function __construct()
{
parent::__construct('goal-edit-form');
$this->setEnctype(Form::ENCTYPE_MULTYPART_FORMDATA);
$lang = OW::getLanguage();
$id = new HiddenField('projectId');
$id->setRequired(true);
$this->addElement($id);
$name = new TextField('name');
$name->setRequired(true);
$name->setLabel($lang->text('ocsfundraising', 'name'));
$this->addElement($name);
$btnSet = array(BOL_TextFormatService::WS_BTN_IMAGE, BOL_TextFormatService::WS_BTN_VIDEO, BOL_TextFormatService::WS_BTN_HTML);
$desc = new WysiwygTextarea('description', $btnSet);
$desc->setRequired(true);
$sValidator = new StringValidator(1, 50000);
$desc->addValidator($sValidator);
$desc->setLabel($lang->text('ocsfundraising', 'description'));
$this->addElement($desc);
$category = new Selectbox('category');
$category->setLabel($lang->text('ocsfundraising', 'category'));
$list = OCSFUNDRAISING_BOL_Service::getInstance()->getCategoryList();
if ($list) {
foreach ($list as $cat) {
$category->addOption($cat->id, $lang->text('ocsfundraising', 'category_' . $cat->id));
}
}
$this->addElement($category);
$target = new TextField('target');
$target->setRequired(true);
$target->setLabel($lang->text('ocsfundraising', 'target_amount'));
$this->addElement($target);
$min = new TextField('min');
$min->setLabel($lang->text('ocsfundraising', 'min_amount'));
$min->setValue(1);
$this->addElement($min);
$end = new DateField('end');
$end->setMinYear(date('Y'));
$end->setMaxYear(date('Y') + 2);
$end->setLabel($lang->text('ocsfundraising', 'end_date'));
$this->addElement($end);
$imageField = new FileField('image');
$imageField->setLabel($lang->text('ocsfundraising', 'image_label'));
$this->addElement($imageField);
$submit = new Submit('edit');
$submit->setLabel($lang->text('ocsfundraising', 'edit'));
$this->addElement($submit);
}
示例7: testUploadMissingRequiredFile
/**
* Test different scenarii for a failed upload : an error occured, no files where provided
*/
public function testUploadMissingRequiredFile()
{
$form = new Form(new Controller(), 'Form', new FieldSet($fileField = new FileField('cv', 'Upload your CV')), new FieldSet(), new RequiredFields('cv'));
// All fields are filled but for some reason an error occured when uploading the file => fails
$fileFieldValue = array('name' => 'aCV.txt', 'type' => 'application/octet-stream', 'tmp_name' => '/private/var/tmp/phpzTQbqP', 'error' => 1, 'size' => 3471);
$fileField->setValue($fileFieldValue);
$this->assertFalse($form->validate(), 'An error occured when uploading a file, but the validator returned true');
// We pass an empty set of parameters for the uploaded file => fails
$fileFieldValue = array();
$fileField->setValue($fileFieldValue);
$this->assertFalse($form->validate(), 'An empty array was passed as parameter for an uploaded file, but the validator returned true');
// We pass an null value for the uploaded file => fails
$fileFieldValue = null;
$fileField->setValue($fileFieldValue);
$this->assertFalse($form->validate(), 'A null value was passed as parameter for an uploaded file, but the validator returned true');
}
示例8: display
static function display($files)
{
$html = "";
foreach ($files as $file) {
$html .= FileField::display($file);
}
return $html;
}
示例9: getFormField
public function getFormField()
{
$field = FileField::create($this->Name, $this->EscapedTitle)->setFieldHolderTemplate('UserFormsField_holder')->setTemplate('UserFormsFileField');
$field->getValidator()->setAllowedExtensions(array_diff(array_filter(Config::inst()->get('File', 'allowed_extensions')), $this->config()->allowed_extensions_blacklist));
$folder = $this->Folder();
if ($folder && $folder->exists()) {
$field->setFolderName(preg_replace("/^assets\\//", "", $folder->Filename));
}
$this->doUpdateFormField($field);
return $field;
}
示例10: Form
function Form()
{
if ($this->request->requestVar('_REDIRECT_BACK_URL')) {
$url = $this->request->requestVar('_REDIRECT_BACK_URL');
} else {
if ($this->request->getHeader('Referer')) {
$url = $this->request->getHeader('Referer');
} else {
$url = Director::baseURL();
}
}
$folder = Folder::find_or_make("ErrorScreenshots");
$whatDidYouTryDoField = new TextareaField('WhatDidYouTryToDo', 'What did you try to do');
$whatDidYouTryDoField->setRows(3);
$whatWentWrongField = new TextareaField('WhatWentWrong', 'What went wrong');
$whatWentWrongField->setRows(3);
$screenshotField = new FileField('Screenshot', 'To take a screenshot press the PRT SCR button on your keyboard, then open MS Word or MS Paint and paste the screenshot. Save the file and then attach (upload) the file here.');
$screenshotField->setFolderName($folder->Name);
$form = new Form($this, 'Form', new FieldList(new TextField('Name'), new TextField('Email'), new TextField('URL', 'What is the URL of the page the error occured (this is the address shown in the address bar (e.g. http://www.mysite.com/mypage/with/errors/)', $url), $whatDidYouTryDoField, $whatWentWrongField, $screenshotField), new FieldList(new FormAction('senderror', 'Submit Error')), new RequiredFields(array("Email", "Name")));
return $form;
}
示例11: __construct
/**
* Class constructor
*/
public function __construct($tpls)
{
parent::__construct('edit-template-form');
$this->setAction(OW::getRouter()->urlFor('VIRTUALGIFTS_CTRL_Admin', 'editTemplate'));
$single = count($tpls) == 1;
$this->setEnctype('multipart/form-data');
$language = OW::getLanguage();
$giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
if ($single) {
$file = new FileField('file');
$file->setLabel($language->text('virtualgifts', 'gift_image'));
$this->addElement($file);
$tpl = $giftService->findTemplateById($tpls[0]);
}
$tplId = new HiddenField('tplId');
$tplId->setRequired(true);
$tplId->setValue(implode('|', $tpls));
$this->addElement($tplId);
if ($giftService->categoriesSetup()) {
$categories = new Selectbox('category');
$categories->setLabel($language->text('virtualgifts', 'category'));
$categories->setOptions($giftService->getCategories());
if ($single && isset($tpl)) {
$categories->setValue($tpl->categoryId);
}
$this->addElement($categories);
}
if (OW::getPluginManager()->isPluginActive('usercredits')) {
$price = new TextField('price');
$price->setLabel($language->text('virtualgifts', 'gift_price'));
if ($single && isset($tpl)) {
$price->setValue($tpl->price);
}
$this->addElement($price);
}
// submit
$submit = new Submit('save');
$submit->setValue($language->text('virtualgifts', 'btn_save'));
$this->addElement($submit);
}
示例12: __construct
public function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
{
if (!$fields) {
$helpHtml = _t('ExcelGroupImportForm.Help1', '<p><a href="{link}">Download sample file</a></p>', array('link' => $controller->Link('downloadsample/Group')));
$helpHtml .= _t('ExcelGroupImportForm.Help2', '<ul>' . '<li>Existing groups are matched by their unique <em>Code</em> value, and updated with any new values from the ' . 'imported file</li>' . '<li>Group hierarchies can be created by using a <em>ParentCode</em> column.</li>' . '<li>Permission codes can be assigned by the <em>PermissionCode</em> column. Existing permission codes are not ' . 'cleared.</li>' . '</ul>');
$importer = new GroupCsvBulkLoader();
$importSpec = $importer->getImportSpec();
$helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
$extensions = array('csv', 'xls', 'xlsx', 'ods', 'txt');
$fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('File', _t('ExcelGroupImportForm.FileFieldLabel', 'File <small><br/>(allowed extensions: {extensions})</small>', array('extensions' => implode(', ', $extensions)))));
$fileField->getValidator()->setAllowedExtensions(array('csv'));
}
if (!$actions) {
$action = new FormAction('doImport', _t('ExcelGroupImportForm.BtnImport', 'Import from file'));
$action->addExtraClass('ss-ui-button');
$actions = new FieldList($action);
}
if (!$validator) {
$validator = new RequiredFields('File');
}
parent::__construct($controller, $name, $fields, $actions, $validator);
$this->addExtraClass('cms');
$this->addExtraClass('import-form');
}
示例13: __construct
public function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
{
if (!$fields) {
$helpHtml = _t('ExcelMemberImportForm.Help1', '<p><a href="{link}">Download sample file</a></p>', array('link' => $controller->Link('downloadsample/Member')));
$helpHtml .= _t('ExcelMemberImportForm.Help2', '<ul>' . '<li>Existing users are matched by their unique <em>Email</em> property, and updated with any new values from ' . 'the imported file.</li>' . '<li>Groups can be assigned by the <em>Groups</em> column. Groups are identified by their <em>Code</em> property, ' . 'multiple groups can be separated by comma. Existing group memberships are not cleared.</li>' . '</ul>');
$importer = new MemberCsvBulkLoader();
$importSpec = $importer->getImportSpec();
$helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
$extensions = array('csv', 'xls', 'xlsx', 'ods', 'txt');
$fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('File', _t('ExcelMemberImportForm.FileFieldLabel', 'File <small><br/>(allowed extensions: {extensions})</small>', array('extensions' => implode(', ', $extensions)))));
$fileField->getValidator()->setAllowedExtensions(ExcelImportExport::getValidExtensions());
}
if (!$actions) {
$action = new FormAction('doImport', _t('ExcelMemberImportForm.BtnImport', 'Import from file'));
$action->addExtraClass('ss-ui-button');
$actions = new FieldList($action);
}
if (!$validator) {
$validator = new RequiredFields('File');
}
parent::__construct($controller, $name, $fields, $actions, $validator);
$this->addExtraClass('cms');
$this->addExtraClass('import-form');
}
示例14: MessageForm
public function MessageForm($request = null, $itemID = 0)
{
if ($itemID == 0) {
$itemID = isset($_REQUEST['ToMemberID']) ? $_REQUEST['ToMemberID'] : 0;
}
$mergeText = "<ul><li>{" . implode("}</li><li>{", PostmarkHelper::MergeTags()) . "}</li></ul>";
$form = new Form($this, 'MessageForm', new FieldList(array(ObjectSelectorField::create('ToMemberID', 'To:')->setValue($itemID)->setSourceObject(Config::inst()->get('PostmarkAdmin', 'member_class'))->setDisplayField('Email'), DropdownField::create('FromID', 'From')->setSource(PostmarkSignature::get()->filter('IsActive', 1)->map('ID', 'Email')->toArray()), TextField::create('Subject'), QuillEditorField::create('Body'), LiteralField::create('MergeTypes', '<div class="varialbes toggle-block">
<h4>Merge Values</h4>
<div class="contents">' . $mergeText . '</div>
</div>'), HiddenField::create('InReplyToID')->setValue(isset($_REQUEST['ReplyToMessageID']) ? $_REQUEST['ReplyToMessageID'] : 0), FileField::create('Attachment_1', 'Attachment One'), FileField::create('Attachment_2', 'Attachment Two'), FileField::create('Attachment_3', 'Attachment Three'), FileField::create('Attachment_4', 'Attachment Four'), FileField::create('Attachment_5', 'Attachment Five'))), new FieldList(FormAction::create('postmessage', 'Sent Message')));
$requiredField = new RequiredFields(array('FromID', 'Subject', 'Body'));
$form->setValidator($requiredField);
$this->extend('updateMessageForm', $form, $itemID);
$form->setFormAction($this->Link('PostmarkMessage/MessageForm'));
return $form;
}
示例15: getFormField
public function getFormField()
{
$field = FileField::create($this->Name, $this->Title);
if ($this->getSetting('Folder')) {
$folder = Folder::get()->byId($this->getSetting('Folder'));
if ($folder) {
$field->setFolderName(preg_replace("/^assets\\//", "", $folder->Filename));
}
}
if ($this->Required) {
// Required validation can conflict so add the Required validation messages
// as input attributes
$errorMessage = $this->getErrorMessage()->HTML();
$field->setAttribute('data-rule-required', 'true');
$field->setAttribute('data-msg-required', $errorMessage);
}
return $field;
}