function imce_upload_submit in IMCE 7
Same name and namespace in other branches
- 6.2 inc/imce.page.inc \imce_upload_submit()
- 6 inc/page.inc \imce_upload_submit()
Submit upload form.
1 string reference to 'imce_upload_submit'
- imce_upload_form in inc/
imce.page.inc - Upload form.
File
- inc/
imce.page.inc, line 328 - Implements the file browser.
Code
function imce_upload_submit($form, &$form_state) {
// Multiple files support. Credit: http://mohitaghera.drupalgardens.com/content/multiple-file-upload-usind-drupal-7-form-api
$num_files = count($_FILES['files']['name']);
for ($i = 0; $i < $num_files; $i++) {
$form_state['redirect'] = FALSE;
$imce =& $form_state['build_info']['args'][0]['imce'];
// Need to provide extension validatior,
// otherwise file_save_upload uses the default.
$validators['file_validate_extensions'] = array(
$imce['extensions'] === '*' ? NULL : $imce['extensions'],
);
$validators['imce_validate_all'] = array(
&$imce,
);
$diruri = imce_dir_uri($imce);
// Save uploaded file.
$replace = variable_get('imce_settings_replace', FILE_EXISTS_RENAME);
// Retrieve the user option when the option is set for the user to decide.
if ($replace == IMCE_RENAME_REPLACE) {
$replace = $form_state['values']['replace'];
}
if ($file = file_save_upload($i, $validators, $diruri, $replace)) {
// Core bug #54223.
if ($replace == FILE_EXISTS_RENAME) {
$name = basename($file->uri);
if ($name != $file->filename) {
$file->filename = $name;
drupal_set_message(t('The file has been renamed to %filename.', array(
'%filename' => $file->filename,
)));
}
}
// Global user may not be the owner.
$file->uid = $imce['uid'];
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
imce_file_register($file);
drupal_set_message(t('%filename has been uploaded.', array(
'%filename' => $file->filename,
)));
// Update file list.
$img = imce_image_info($file->uri);
$file->width = $img ? $img['width'] : 0;
$file->height = $img ? $img['height'] : 0;
imce_add_file($file, $imce);
// Create thumbnails.
if (isset($form_state['values']['thumbnails']) && $img) {
imce_create_thumbnails($file->filename, $imce, $form_state['values']['thumbnails']);
}
}
else {
drupal_set_message(t('Upload failed.'), 'error');
}
}
}