当前位置: 首页>>代码示例>>PHP>>正文


PHP FormValidator::addFile方法代码示例

本文整理汇总了PHP中FormValidator::addFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FormValidator::addFile方法的具体用法?PHP FormValidator::addFile怎么用?PHP FormValidator::addFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FormValidator的用法示例。


在下文中一共展示了FormValidator::addFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

     break;
 case 'edit_icon':
     $tool = CourseHome::getTool($id);
     if (empty($tool)) {
         api_not_allowed(true);
     }
     $interbreadcrumb[] = array('url' => api_get_self() . '?' . api_get_cidreq(), 'name' => get_lang('CustomizeIcons'));
     $toolName = $tool['name'];
     $currentUrl = api_get_self() . '?action=edit_icon&id=' . $id . '&' . api_get_cidreq();
     $form = new FormValidator('icon_edit', 'post', $currentUrl);
     $form->addHeader(get_lang('EditIcon'));
     $form->addHtml('<div class="col-md-7">');
     $form->addText('name', get_lang('Name'));
     $form->addText('link', get_lang('Links'));
     $allowed_picture_types = array('jpg', 'jpeg', 'png');
     $form->addFile('icon', get_lang('CustomIcon'));
     $form->addRule('icon', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
     $form->addSelect('target', get_lang('LinkTarget'), ['_self' => get_lang('LinkOpenSelf'), '_blank' => get_lang('LinkOpenBlank')]);
     $form->addSelect('visibility', get_lang('Visibility'), array(1 => get_lang('Visible'), 0 => get_lang('Invisible')));
     $form->addTextarea('description', get_lang('Description'), array('rows' => '3', 'cols' => '40'));
     $form->addButtonUpdate(get_lang('Update'));
     $form->addHtml('</div>');
     $form->addHtml('<div class="col-md-5">');
     if (isset($tool['custom_icon']) && !empty($tool['custom_icon'])) {
         $form->addLabel(get_lang('CurrentIcon'), Display::img(CourseHome::getCustomWebIconPath() . $tool['custom_icon']));
         $form->addCheckBox('delete_icon', null, get_lang('DeletePicture'));
     }
     $form->addHtml('</div>');
     $form->setDefaults($tool);
     $content = $form->returnForm();
     if ($form->validate()) {
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:31,代码来源:tools.php

示例2: display_new_comment_form

 /**
  * Displays the form to create a new post
  * @author Toon Keppens
  *
  * @param Integer $blog_id
  */
 public static function display_new_comment_form($blog_id, $post_id, $title)
 {
     $form = new FormValidator('add_post', 'post', api_get_path(WEB_CODE_PATH) . "blog/blog.php?action=view_post&blog_id=" . intval($blog_id) . "&post_id=" . intval($post_id) . "&" . api_get_cidreq(), null, array('enctype' => 'multipart/form-data'));
     $header = get_lang('AddNewComment');
     if (isset($_GET['task_id'])) {
         $header = get_lang('ExecuteThisTask');
     }
     $form->addHeader($header);
     $form->addText('title', get_lang('Title'));
     $config = array();
     if (!api_is_allowed_to_edit()) {
         $config['ToolbarSet'] = 'ProjectComment';
     } else {
         $config['ToolbarSet'] = 'ProjectCommentStudent';
     }
     $form->addHtmlEditor('comment', get_lang('Comment'), false, false, $config);
     $form->addFile('user_upload', get_lang('AddAnAttachment'));
     $form->addTextarea('post_file_comment', get_lang('FileComment'));
     $form->addHidden('action', null);
     $form->addHidden('comment_parent_id', 0);
     if (isset($_GET['task_id'])) {
         $form->addHidden('new_task_execution_submit', 'true');
         $form->addHidden('task_id', intval($_GET['task_id']));
     } else {
         $form->addHidden('new_comment_submit', 'true');
     }
     $form->addButton('save', get_lang('Save'));
     $form->display();
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:35,代码来源:blog.lib.php

示例3: handle_stylesheets


//.........这里部分代码省略.........
            }
        }
        closedir($handle);
    }
    // Sort styles in alphabetical order.
    asort($list_of_names);
    $select_list = array();
    foreach ($list_of_names as $style_dir => $item) {
        $select_list[$style_dir] = $item;
    }
    $styles =& $form_change->addElement('select', 'style', get_lang('NameStylesheet'), $select_list);
    $styles->setSelected($selected);
    if ($form_change->validate()) {
        // Submit stylesheets.
        if (isset($_POST['save'])) {
            store_stylesheets();
            Display::display_normal_message(get_lang('Saved'));
        }
        if (isset($_POST['download'])) {
            $arch = api_get_path(SYS_ARCHIVE_PATH) . $safe_style_dir . '.zip';
            $dir = api_get_path(SYS_CSS_PATH) . 'themes/' . $safe_style_dir;
            if (is_dir($dir)) {
                $zip = new PclZip($arch);
                // Remove path prefix except the style name and put file on disk
                $zip->create($dir, PCLZIP_OPT_REMOVE_PATH, substr($dir, 0, -strlen($safe_style_dir)));
                //@TODO: use more generic script to download.
                $str = '<a class="btn btn-primary btn-large" href="' . api_get_path(WEB_CODE_PATH) . 'course_info/download.php?archive=' . str_replace(api_get_path(SYS_ARCHIVE_PATH), '', $arch) . '">' . get_lang('ClickHereToDownloadTheFile') . '</a>';
                Display::display_normal_message($str, false);
            } else {
                Display::addFlash(Display::return_message(get_lang('FileNotFound'), 'warning'));
            }
        }
    }
    $logoForm = new FormValidator('logo_upload', 'post', 'settings.php?category=Stylesheets#tabs-2');
    $logoForm->addHtml(Display::return_message(sprintf(get_lang('TheLogoMustBeSizeXAndFormatY'), '250 x 70', 'PNG'), 'info'));
    $dir = api_get_path(SYS_PUBLIC_PATH) . 'css/themes/' . $selected . '/images/';
    $url = api_get_path(WEB_CSS_PATH) . 'themes/' . $selected . '/images/';
    $logoFileName = 'header-logo.png';
    $newLogoFileName = 'header-logo-custom.png';
    if (is_file($dir . $newLogoFileName)) {
        $logoForm->addLabel(get_lang('CurrentLogo'), '<img id="header-logo-custom" src="' . $url . $newLogoFileName . '?' . time() . '">');
    } else {
        $logoForm->addLabel(get_lang('CurrentLogo'), '<img id="header-logo-custom" src="' . $url . $logoFileName . '?' . time() . '">');
    }
    $logoForm->addFile('new_logo', get_lang('UpdateLogo'));
    $allowedFileTypes = ['png'];
    if (isset($_POST['logo_reset'])) {
        if (is_file($dir . $newLogoFileName)) {
            unlink($dir . $newLogoFileName);
            Display::display_normal_message(get_lang('ResetToTheOriginalLogo'));
            echo '<script>' . '$("#header-logo").attr("src","' . $url . $logoFileName . '");' . '</script>';
        }
    } elseif (isset($_POST['logo_upload'])) {
        $logoForm->addRule('new_logo', get_lang('InvalidExtension') . ' (' . implode(',', $allowedFileTypes) . ')', 'filetype', $allowedFileTypes);
        $logoForm->addRule('new_logo', get_lang('ThisFieldIsRequired'), 'required');
        if ($logoForm->validate()) {
            $imageInfo = getimagesize($_FILES['new_logo']['tmp_name']);
            $width = $imageInfo[0];
            $height = $imageInfo[1];
            if ($width <= 250 && $height <= 70) {
                if (is_file($dir . $newLogoFileName)) {
                    unlink($dir . $newLogoFileName);
                }
                $status = move_uploaded_file($_FILES['new_logo']['tmp_name'], $dir . $newLogoFileName);
                if ($status) {
                    Display::display_normal_message(get_lang('NewLogoUpdated'));
                    echo '<script>' . '$("#header-logo").attr("src","' . $url . $newLogoFileName . '");' . '</script>';
                } else {
                    Display::display_error_message('Error - ' . get_lang('UplNoFileUploaded'));
                }
            } else {
                Display::display_error_message('Error - ' . get_lang('InvalidImageDimensions'));
            }
        }
    }
    if ($is_style_changeable) {
        $group = [$form_change->addButtonSave(get_lang('SaveSettings'), 'save', true), $form_change->addButtonPreview(get_lang('Preview'), 'preview', true), $form_change->addButtonDownload(get_lang('Download'), 'download', true)];
        $form_change->addGroup($group);
        $logoGroup = [$logoForm->addButtonUpload(get_lang('Upload'), 'logo_upload', true), $logoForm->addButtonCancel(get_lang('Reset'), 'logo_reset', true)];
        $logoForm->addGroup($logoGroup);
        if ($show_upload_form) {
            echo '<script>
            $(function() {
                $( "#tabs" ).tabs();
            });
            </script>';
            echo Display::tabs(array(get_lang('Update'), get_lang('UpdateLogo'), get_lang('UploadNewStylesheet')), array($form_change->return_form(), $logoForm->return_form(), $form->return_form()));
        } else {
            $form_change->display();
        }
        //Little hack to update the logo image in update form when submiting
        if (isset($_POST['logo_reset'])) {
            echo '<script>' . '$("#header-logo-custom").attr("src","' . $url . $logoFileName . '");' . '</script>';
        } elseif (isset($_POST['logo_upload']) && is_file($dir . $newLogoFileName)) {
            echo '<script>' . '$("#header-logo-custom").attr("src","' . $url . $newLogoFileName . '");' . '</script>';
        }
    } else {
        $form_change->freeze();
    }
}
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:101,代码来源:settings.lib.php


注:本文中的FormValidator::addFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。