function imce_upload_submit in IMCE 6.2
Same name and namespace in other branches
- 6 inc/page.inc \imce_upload_submit()
- 7 inc/imce.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 281 - Implements the file browser.
Code
function imce_upload_submit($form, &$form_state) {
$form_state['redirect'] = FALSE;
$imce =& $form['#parameters'][2]['imce'];
$validators = array(
'imce_validate_all' => array(
&$imce,
),
);
$dirpath = file_directory_path() . ($imce['dir'] == '.' ? '' : '/' . $imce['dir']);
//save uploaded file.
$replace = variable_get('imce_settings_replace', FILE_EXISTS_RENAME);
if ($file = file_save_upload('imce', $validators, $dirpath, $replace)) {
//core bug #203204.
@chmod($file->filepath, 0664);
//core bug #54223.
if ($replace == FILE_EXISTS_RENAME) {
$name = basename($file->filepath);
if ($name != $file->filename) {
$file->filename = $name;
drupal_set_message(t('The file has been renamed to %filename.', array(
'%filename' => $file->filename,
)));
}
}
elseif ($replace == FILE_EXISTS_REPLACE) {
//check duplicates
if ($_file = db_fetch_object(db_query("SELECT fid FROM {files} WHERE filepath = '%s' AND fid <> %d", $file->filepath, $file->fid))) {
db_query("DELETE FROM {files} WHERE fid = %d", $file->fid);
$file->fid = $_file->fid;
}
}
$file->uid = $imce['uid'];
//global user may not be the owner.
$file->status = FILE_STATUS_PERMANENT;
//make permanent
drupal_write_record('files', $file, array(
'fid',
));
//update
imce_file_register($file);
drupal_set_message(t('%filename has been uploaded.', array(
'%filename' => $file->filename,
)));
//update file list
$img = imce_image_info($file->filepath);
$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');
}
}