• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP file_save_upload函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中file_save_upload函数的典型用法代码示例。如果您正苦于以下问题:PHP file_save_upload函数的具体用法?PHP file_save_upload怎么用?PHP file_save_upload使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: singular_settings

/**
 * Implementation of hook_settings() for themes.
 */
function singular_settings($settings)
{
    // Add js & css
    drupal_add_css('misc/farbtastic/farbtastic.css', 'module', 'all', FALSE);
    drupal_add_js('misc/farbtastic/farbtastic.js');
    drupal_add_js(drupal_get_path('theme', 'singular') . '/js/settings.js');
    drupal_add_css(drupal_get_path('theme', 'singular') . '/css/settings.css');
    file_check_directory(file_directory_path(), FILE_CREATE_DIRECTORY, 'file_directory_path');
    // Check for a new uploaded logo, and use that instead.
    if ($file = file_save_upload('background_file', array('file_validate_is_image' => array()))) {
        $parts = pathinfo($file->filename);
        $filename = 'singular_background.' . $parts['extension'];
        if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
            $settings['background_path'] = $file->filepath;
        }
    }
    $form = array();
    $form['layout'] = array('#title' => t('Layout'), '#type' => 'select', '#options' => array('fixed' => t('Fixed width'), 'fluid' => t('Fluid width')), '#default_value' => !empty($settings['layout']) ? $settings['layout'] : 'fixed');
    $form['messages'] = array('#type' => 'fieldset', '#tree' => FALSE, '#title' => t('Autoclose messages'), '#descriptions' => t('Select the message types to close automatically after a few seconds.'));
    $form['messages']['autoclose'] = array('#type' => 'checkboxes', '#options' => array('status' => t('Status'), 'warning' => t('Warning'), 'error' => t('Error')), '#default_value' => !empty($settings['autoclose']) ? $settings['autoclose'] : array('status'));
    $form['style'] = array('#title' => t('Styles'), '#type' => 'select', '#options' => singular_get_styles(), '#default_value' => !empty($settings['style']) ? $settings['style'] : 'sea');
    $form['custom'] = array('#tree' => FALSE, '#type' => 'fieldset', '#attributes' => array('class' => $form['style']['#default_value'] == 'custom' ? 'singular-custom-settings' : 'singular-custom-settings hidden'));
    $form['custom']['background_file'] = array('#type' => 'file', '#title' => t('Background image'), '#maxlength' => 40);
    if (!empty($settings['background_path'])) {
        $form['custom']['background_preview'] = array('#type' => 'markup', '#value' => !empty($settings['background_path']) ? theme('image', $settings['background_path'], NULL, NULL, array('width' => '100'), FALSE) : '');
    }
    $form['custom']['background_path'] = array('#type' => 'value', '#value' => !empty($settings['background_path']) ? $settings['background_path'] : '');
    $form['custom']['background_color'] = array('#title' => t('Background color'), '#type' => 'textfield', '#size' => '7', '#maxlength' => '7', '#default_value' => !empty($settings['background_color']) ? $settings['background_color'] : '#888888', '#suffix' => '<div id="singular-colorpicker"></div>');
    $form['custom']['background_repeat'] = array('#title' => t('Tile'), '#type' => 'select', '#options' => array('no-repeat' => t('Don\'t tile'), 'repeat-x' => t('Horizontal'), 'repeat-y' => t('Vertical'), 'repeat' => t('Both')), '#default_value' => !empty($settings['background_repeat']) ? $settings['background_repeat'] : 'no-repeat');
    return $form;
}
开发者ID:szczym,项目名称:tutturu,代码行数:34,代码来源:theme-settings.php


示例2: addStreamFormSubmit

 function addStreamFormSubmit($form_id, $form_values)
 {
     module_load_include('inc', 'Fedora_Repository', 'api/fedora_utils');
     module_load_include('inc', 'Fedora_Repository', 'api/fedora_item');
     module_load_include('php', 'Fedora_Repository', 'ObjectHelper');
     $types = array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.wordperfect', 'application/wordperfect', 'application/vnd.oasis.opendocument.text', 'text/rtf', 'application/rtf', 'application/msword', 'application/vnd.ms-powerpoint', 'application/pdf');
     global $user;
     /* TODO Modify the validators array to suit your needs.
        This array is used in the revised file_save_upload */
     $fileObject = file_save_upload('file_uploaded');
     if (!in_array($fileObject->filemime, $types)) {
         drupal_set_message(t('The detected mimetype %s is not supported', array('%s' => $fileObject->filemime)), 'error');
         return false;
     }
     file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME');
     $objectHelper = new ObjectHelper();
     $pid = $form_values['pid'];
     $fedora_item = new Fedora_Item($pid);
     $test = NULL;
     $test = $fedora_item->add_datastream_from_file($fileObject->filepath, 'OBJ');
     if ($test) {
         $this->updateMODSStream($form_values['pid'], $form_values['version'], $form_values['usage']);
     }
     file_delete($fileObject->filepath);
     return true;
 }
开发者ID:roblib,项目名称:islandora_scholar_upei,代码行数:26,代码来源:IrClass.php


示例3: black_lagoon_settings_submit

/**
 * Save settings data.
 */
function black_lagoon_settings_submit($form, &$form_state)
{
    $settings = array();
    // Update image field
    foreach ($form_state['input']['images'] as $image) {
        if (is_array($image)) {
            $image = $image['image'];
            if ($image['image_delete']) {
                // Delete banner file
                file_unmanaged_delete($image['image_path']);
                // Delete banner thumbnail file
                file_unmanaged_delete($image['image_thumb']);
            } else {
                // Update image
                $settings[] = $image;
            }
        }
    }
    // Check for a new uploaded file, and use that if available.
    if ($file = file_save_upload('image_upload')) {
        $file->status = FILE_STATUS_PERMANENT;
        if ($image = _black_lagoon_save_image($file)) {
            // Put new image into settings
            $settings[] = $image;
        }
    }
    // Save settings
    black_lagoon_set_banners($settings);
}
开发者ID:jcubed22,项目名称:Drupal_Space_Pirates,代码行数:32,代码来源:theme-settings.php


示例4: nuboot_radix_settings_submit

/**
 * Implements hook_setings_submit().
 */
function nuboot_radix_settings_submit($form, &$form_state)
{
    $settings = array();
    // If the user entered a path relative to the system files directory for
    // for the hero unit, store a public:// URI so the theme system can handle it.
    if (!empty($values['hero_path'])) {
        $values['hero_path'] = _system_theme_settings_validate_path($values['hero_path']);
    }
    // Get the previous value.
    $previous = $form['hero']['hero_path']['#default_value'];
    if ($previous !== 'profiles/dkan/themes/contrib/nuboot_radix/assets/images/hero.jpg') {
        $previous = 'public://' . $previous;
    } else {
        $previous = FALSE;
    }
    if ($file = file_save_upload('hero_upload')) {
        $parts = pathinfo($file->filename);
        $destination = 'public://' . $parts['basename'];
        $file->status = FILE_STATUS_PERMANENT;
        if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
            $_POST['hero_path'] = $form_state['values']['hero_path'] = $destination;
            // If new file has a different name than the old one, delete the old.
            if ($previous && $destination != $previous) {
                drupal_unlink($previous);
            }
        }
    } else {
        // Avoid error when the form is submitted without specifying a new image.
        $_POST['hero_path'] = $form_state['values']['hero_path'] = $previous;
    }
}
开发者ID:TwoSixtyNine,项目名称:dkan-drops-7,代码行数:34,代码来源:theme-settings.php


示例5: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Process the upload and perform validation. Note: we're using the
     // form value for the $replace parameter.
     if (!$form_state->isValueEmpty('file_subdir')) {
         $destination = 'temporary://' . $form_state->getValue('file_subdir');
         file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
     } else {
         $destination = FALSE;
     }
     // Setup validators.
     $validators = array();
     if ($form_state->getValue('is_image_file')) {
         $validators['file_validate_is_image'] = array();
     }
     if ($form_state->getValue('allow_all_extensions')) {
         $validators['file_validate_extensions'] = array();
     } elseif (!$form_state->isValueEmpty('extensions')) {
         $validators['file_validate_extensions'] = array($form_state->getValue('extensions'));
     }
     $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace'));
     if ($file) {
         $form_state->setValue('file_test_upload', $file);
         drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
         drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename())));
         drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
         drupal_set_message(t('You WIN!'));
     } elseif ($file === FALSE) {
         drupal_set_message(t('Epic upload FAIL!'), 'error');
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:34,代码来源:FileTestForm.php


示例6: flux_theme_settings_validate

/**
 * Validate handler where we actually save the files...
 */
function flux_theme_settings_validate($form, &$form_state)
{
    // Handle file uploads.
    $validators = array('file_validate_is_image' => array());
    // Check for a new uploaded logo.
    $file = file_save_upload('cover_photo_upload', $validators);
    if (isset($file)) {
        // File upload was attempted.
        if ($file) {
            // Put the temporary file in form_values so we can save it on submit.
            $form_state['values']['cover_photo_upload'] = $file;
        } else {
            // File upload failed.
            form_set_error('cover_photo_upload', t('The image could not be uploaded.'));
        }
    }
    $validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg'));
    // If the user provided a path for a logo or favicon file, make sure a file
    // exists at that path.
    if ($form_state['values']['cover_photo_path']) {
        $path = flux_system_theme_settings_validate_path($form_state['values']['cover_photo_path']);
        if (!$path) {
            form_set_error('cover_photo_path', t('The custom path is invalid.'));
        }
    }
}
开发者ID:sheldonrampton,项目名称:pushtape-drops,代码行数:29,代码来源:theme-settings.php


示例7: platon_form_system_theme_settings_alter_validate

/**
 * Validation callback for platon_form_system_theme_settings_alter().
 */
function platon_form_system_theme_settings_alter_validate($form, &$form_state)
{
    if (!empty($_FILES['files']['name']['platon_header_image_upload'])) {
        $file = file_save_upload('platon_header_image_upload', array('file_validate_is_image' => array(), 'file_validate_extensions' => array('png gif jpg jpeg')), 'public://');
        if ($file) {
            $file->status = FILE_STATUS_PERMANENT;
            file_save($file);
            $form_state['storage']['header_file'] = $file;
        } else {
            form_set_error('platon_header_image_upload', t("Couldn't upload file."));
        }
    }
    if (!empty($_FILES['files']['name']['platon_home_page_image_upload'])) {
        $file = file_save_upload('platon_home_page_image_upload', array('file_validate_is_image' => array(), 'file_validate_extensions' => array('png gif jpg jpeg')), 'public://');
        if ($file) {
            $file->status = FILE_STATUS_PERMANENT;
            file_save($file);
            $form_state['storage']['home_file'] = $file;
        } else {
            form_set_error('platon_home_page_image_upload', t("Couldn't upload file."));
        }
    }
    if (!empty($form_state['values']['platon_css_override_content'])) {
        if ($fid = _platon_store_css_override_file($form_state['values']['platon_css_override_content'])) {
            $form_state['storage']['css_fid'] = $fid;
        } else {
            form_set_error('platon_css_override_content', t("Could not save the CSS in a file. Perhaps the server has no write access. Check your public files folder permissions."));
        }
    }
}
开发者ID:sirusdas,项目名称:opigno,代码行数:33,代码来源:theme-settings.php


示例8: daycare_background_validate

/**
 * implements ddaycare_background_validate
 */
function daycare_background_validate($element, &$form_state)
{
    global $base_url;
    $validators = array('file_validate_is_image' => array());
    $file = file_save_upload('background', $validators, "public://", FILE_EXISTS_REPLACE);
    if ($file) {
        // change file's status from temporary to permanent and update file database
        $file->status = FILE_STATUS_PERMANENT;
        file_save($file);
        $file_url = file_create_url($file->uri);
        $file_url = str_ireplace($base_url . '/', '', $file_url);
        // set to form
        $form_state['values']['bg_file'] = $file_url;
    }
}
开发者ID:puridi,项目名称:Hotel,代码行数:18,代码来源:theme-settings.php


示例9: bulkSavePictures

function bulkSavePictures(&$form_state)
{
    $num_files = count($_FILES['files']['name']);
    for ($i = 0; $i < $num_files; $i++) {
        $file = file_save_upload($i, array('file_validate_is_image' => array(), 'file_validate_extensions' => array('png gif jpg jpeg')));
        if ($file) {
            if ($file = file_move($file, 'public://')) {
                $form_state['values']['file'][$i] = $file;
            } else {
                form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
            }
        } else {
            form_set_error('file', t('No file was uploaded.'));
        }
    }
}
开发者ID:ChapResearch,项目名称:CROMA,代码行数:16,代码来源:pictureFunctions.php


示例10: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Validate options.
     $roles = $form_state->getValue(['config', 'roles']);
     $roles_selected = array_filter($roles, function ($item) {
         return $item;
     });
     if (empty($roles_selected)) {
         $form_state->setErrorByName('roles', $this->t('Please select at least one role to apply to the imported user(s).'));
     }
     // Validate file.
     $this->file = file_save_upload('file', $form['file']['#upload_validators']);
     if (!$this->file[0]) {
         $form_state->setErrorByName('file');
     }
 }
开发者ID:steveoliver,项目名称:user_import,代码行数:19,代码来源:UserImportForm.php


示例11: open_framework_settings_validate

function open_framework_settings_validate($form, &$form_state)
{
    $validators = array('file_validate_is_image' => array());
    // Check for a new uploaded logo.
    $file = file_save_upload('body_bg_upload', $validators);
    if (isset($file)) {
        // File upload was attempted.
        if ($file) {
            // Put the temporary file in form_values so we can save it on submit.
            $form_state['values']['body_bg_upload'] = $file;
        } else {
            // File upload failed.
            form_set_error('body_bg_upload', t('The background image could not be uploaded.'));
        }
    }
}
开发者ID:Arabidopsis-Information-Portal,项目名称:araport-portal,代码行数:16,代码来源:theme-settings.php


示例12: intranet_system_theme_settings_submit

function intranet_system_theme_settings_submit($form, &$form_state)
{
    $settings = array();
    $file = file_save_upload('footer_image_upload');
    $bg_imags = array('bg_image_upload' => 'bg_image_path', 'header_image_upload' => 'header_image_path', 'footer_image_upload' => 'footer_image_path');
    foreach ($bg_imags as $upload => $path) {
        // Check for a new uploaded file, and use that if available.
        if ($file = file_save_upload($upload)) {
            $parts = pathinfo($file->filename);
            $destination = 'public://' . $parts['basename'];
            $file->status = FILE_STATUS_PERMANENT;
            if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
            }
            $form_state['values'][$path] = $destination;
        }
    }
}
开发者ID:cap-mayank,项目名称:intranet,代码行数:17,代码来源:theme-settings.php


示例13: parallax_bg_region5_validate

function parallax_bg_region5_validate($element, &$form_state)
{
    global $base_url;
    $validateFile = array('file_validate_is_image' => array());
    $UploadedFile = file_save_upload('parallax_bg_region5_image', $validateFile, "public://", FILE_EXISTS_REPLACE);
    if ($form_state['values']['delete_parallax_bg_region5_image'] == TRUE) {
        file_unmanaged_delete($form_state['values']['parallax_bg_region5_preview']);
        $form_state['values']['parallax_bg_region5_preview'] = NULL;
    }
    if ($UploadedFile) {
        $UploadedFile->status = FILE_STATUS_PERMANENT;
        file_save($UploadedFile);
        $file_url = file_create_url($UploadedFile->uri);
        $file_url = str_ireplace($base_url, '', $file_url);
        // set to form
        $form_state['values']['parallax_bg_region5_preview'] = $file_url;
    }
}
开发者ID:ApsGitAdmin,项目名称:APS,代码行数:18,代码来源:parallax-image-validate.php


示例14: hosting_themes_settings_submit

function hosting_themes_settings_submit($form, &$form_state)
{
    // Get the previous value
    $previous = 'public://' . $form['contact']['contact_icon']['#default_value'];
    $file = file_save_upload('contact_icon_upload');
    if ($file) {
        $parts = pathinfo($file->filename);
        $destination = 'public://' . $parts['basename'];
        $file->status = FILE_STATUS_PERMANENT;
        if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
            $_POST['contact_icon'] = $form_state['values']['contact_icon'] = $destination;
            if ($destination != $previous) {
                return;
            }
        }
    } else {
        // Avoid error when the form is submitted without specifying a new image
        $_POST['contact_icon'] = $form_state['values']['contact_icon'] = $previous;
    }
}
开发者ID:henrytran9x,项目名称:hosting,代码行数:20,代码来源:theme-settings.php


示例15: _agency_1_theme_settings_map

function _agency_1_theme_settings_map($form, &$form_state)
{
    $validators = array('file_validate_is_image' => array());
    $file = file_save_upload('background_file', $validators);
    $map_file = file_save_upload('footer_contact_us_map_image', $validators);
    //Map image
    if (isset($map_file)) {
        // File upload was attempted.
        if ($map_file) {
            // Move the file, into the Drupal file system
            if ($map_filename = file_unmanaged_copy($map_file->uri, 'public://background_images', FILE_EXISTS_RENAME)) {
                //resize, if necessary
                $map_resized = image_load($map_file->uri);
                list($map_width, $map_height) = getimagesize($map_file->uri);
                if ($map_width > 150 || $map_height > 150) {
                    if ($map_width / $map_height >= 1) {
                        image_scale($map_resized, 150);
                    } else {
                        image_scale($map_resized, null, 150);
                    }
                    image_save($map_resized, $map_filename, FILE_EXISTS_RENAME);
                    $map_resized->status = FILE_STATUS_PERMANENT;
                    drupal_set_message('Uploaded image was greater than 150px.  Image has been resized.');
                }
                //end resize
                unset($form['footer_contact_us']['settings']['footer_contact_us_map_path']);
                $form['footer_contact_us']['settings']['footer_contact_us_map_path']['#value'] = $map_filename;
                $form['footer_contact_us_map_path']['#parents'] = array('footer_contact_us_map_path');
                form_set_value($form['footer_contact_us_map_path'], file_create_url($map_filename), $form_state);
                watchdog('Theme Settings', 'New Footer Map Image uploaded: ' . file_create_url($map_filename));
                drupal_set_message('Map Image uploaded.  URL: ' . file_create_url($map_filename));
            } else {
                form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
            }
        } else {
            // File upload failed.
            form_set_error('background_file', t('The image could not be uploaded.'));
        }
    }
}
开发者ID:ehazell,项目名称:AZDWR,代码行数:40,代码来源:theme-settings.php


示例16: academy_settings_submit

function academy_settings_submit($form, &$form_state)
{
    $settings = array();
    // Get the previous value
    $previous = 'public://' . $form['bg_image']['bg_path']['#default_value'];
    $file = file_save_upload('bg_upload');
    if ($file) {
        $parts = pathinfo($file->filename);
        $destination = 'public://' . $parts['basename'];
        $file->status = FILE_STATUS_PERMANENT;
        if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
            $_POST['bg_path'] = $form_state['values']['bg_path'] = $destination;
            // If new file has a different name than the old one, delete the old
            if ($destination != $previous) {
                drupal_unlink($previous);
            }
        }
    } else {
        // Avoid error when the form is submitted without specifying a new image
        $_POST['bg_path'] = $form_state['values']['bg_path'] = $previous;
    }
}
开发者ID:EWB,项目名称:grh,代码行数:22,代码来源:theme-settings.php


示例17: saveFile

 /**
  * Save uploaded file. Call this from the form submit handler
  * @return
  * 		true if success, false if not
  * @param object $file_field[optional]
  * 		field name of the form
  * @param object $file_type[optional]
  * 		acceptable MIME type substring, e.g. 'image/'
  */
 function saveFile($file_field = 'attachment', $file_type = '')
 {
     if (isset($_FILES[$file_field]) && !empty($_FILES[$file_field]['name'])) {
         // we only care about single file uploads here
         $uploadkey = '';
         //the original name of the file is $_FILES[$file_field]['name'][$upload_key]
         if (is_array($_FILES[$file_field]['name'])) {
             foreach ($_FILES[$file_field]['name'] as $key => $val) {
                 $uploadkey = $key;
                 break;
             }
         }
         // valid attachment ?
         if ($file_type != '') {
             if (!eregi($file_type, $uploadkey == '' ? $_FILES[$file_field]['type'] : $_FILES[$file_field]['type'][$uploadkey])) {
                 // invalid data mime type found
                 return false;
             }
         }
         //01. we store the file into the file_managed table temporarily, and get the file object
         $file = file_save_upload($uploadkey, array(), NULL);
         //02. we get the file id in the file_managed table, and by using the file id together with the original filename, we create the new filename
         //also, we store the file id into the last_upload_id
         $filename = $file->fid . $_FILES[$file_field]['name'][$uploadkey];
         $this->last_uploaded_id = $file->fid;
         //03. we save the file to be uploaded into the public file directory.
         $file = file_move($file, 'public://' . $filename, FILE_EXISTS_REPLACE);
         //04. set file the status to be permanently and save the file.
         $file->status = FILE_STATUS_PERMANENT;
         variable_set('file_id', $file->fid);
         file_save($file);
         //upload success;
         return true;
     } else {
         // invalid attachment data found
         return false;
     }
 }
开发者ID:zevergreenz,项目名称:Drupal,代码行数:47,代码来源:cvwobase_d7_fileupload.php


示例18: asu_webspark_bootstrap_settings_validate

function asu_webspark_bootstrap_settings_validate($form, &$form_state)
{
    // Handle file uploads.
    $validators = array('file_validate_is_image' => array());
    // Check for a new uploaded logo.
    $file = file_save_upload('picture_upload', $validators);
    if (isset($file)) {
        // File upload was attempted.
        if ($file) {
            // Put the temporary file in form_values so we can save it on submit.
            $form_state['values']['picture_upload'] = $file;
        } else {
            // File upload failed.
            form_set_error('logo_picture', t('The logo could not be uploaded.'));
        }
    }
    if ($form_state['values']['picture_path']) {
        $path = _system_theme_settings_validate_path($form_state['values']['picture_path']);
        if (!$path) {
            form_set_error('picture_path', t('The custom logo path is invalid.'));
        }
    }
}
开发者ID:niner9,项目名称:webspark-drops-drupal7,代码行数:23,代码来源:theme-settings.php


示例19: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Process the upload and perform validation. Note: we're using the
     // form value for the $replace parameter.
     if (!$form_state->isValueEmpty('file_subdir')) {
         $destination = 'temporary://' . $form_state->getValue('file_subdir');
         file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
     } else {
         $destination = FALSE;
     }
     // Setup validators.
     $validators = array();
     if ($form_state->getValue('is_image_file')) {
         $validators['file_validate_is_image'] = array();
     }
     if ($form_state->getValue('allow_all_extensions')) {
         $validators['file_validate_extensions'] = array();
     } elseif (!$form_state->isValueEmpty('extensions')) {
         $validators['file_validate_extensions'] = array($form_state->getValue('extensions'));
     }
     // The test for drupal_move_uploaded_file() triggering a warning is
     // unavoidable. We're interested in what happens afterwards in
     // file_save_upload().
     if (\Drupal::state()->get('file_test.disable_error_collection')) {
         define('SIMPLETEST_COLLECT_ERRORS', FALSE);
     }
     $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace'));
     if ($file) {
         $form_state->setValue('file_test_upload', $file);
         drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
         drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename())));
         drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
         drupal_set_message(t('You WIN!'));
     } elseif ($file === FALSE) {
         drupal_set_message(t('Epic upload FAIL!'), 'error');
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:40,代码来源:FileTestForm.php


示例20: opUpload

 /**
  * Operation handler: upload.
  */
 public function opUpload(ImceFM $fm)
 {
     $folder = $fm->activeFolder;
     if (!$folder || !$folder->getPermission('upload_files')) {
         return;
     }
     // Prepare save options
     $destination = $folder->getUri();
     $replace = $fm->getConf('replace', FILE_EXISTS_RENAME);
     $validators = array();
     // Extension validator
     $exts = $fm->getConf('extensions', '');
     $validators['file_validate_extensions'] = array($exts === '*' ? NULL : $exts);
     // File size and user quota validator
     $validators['file_validate_size'] = array($fm->getConf('maxsize'), $fm->getConf('quota'));
     // Image resolution validator.
     $width = $fm->getConf('maxwidth');
     $height = $fm->getConf('maxheight');
     if ($width || $height) {
         $validators['file_validate_image_resolution'] = array(($width ? $width : 10000) . 'x' . ($height ? $height : 10000));
     }
     // Name validator
     $validators[get_class($this) . '::validateFileName'] = array($fm);
     // Save files
     if ($files = file_save_upload('imce', $validators, $destination, NULL, $replace)) {
         $fs = \Drupal::service('file_system');
         foreach (array_filter($files) as $file) {
             // Set status and save
             $file->setPermanent();
             $file->save();
             // Add to the folder and to js response.
             $name = $fs->basename($file->getFileUri());
             $folder->addFile($name)->addToJs();
         }
     }
 }
开发者ID:aakb,项目名称:cfia,代码行数:39,代码来源:Upload.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP file_scan_directory函数代码示例发布时间:2022-05-15
下一篇:
PHP file_save_draft_area_files函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap