function webfm_upload in Web File Manager 5.2
Same name and namespace in other branches
- 5 webfm.module \webfm_upload()
Called by upload form submit
1 string reference to 'webfm_upload'
- webfm_menu in ./
webfm.module - Implementation of hook_menu().
File
- ./
webfm.module, line 689
Code
function webfm_upload() {
//Get the destination path from the edit-webfmuploadpath hidden field in the upload form
$json_data = array();
if ($_POST['webfmuploadpath']) {
$dest = file_directory_path() . $_POST['webfmuploadpath'];
$db_check = TRUE;
// Save new file uploads to tmp dir.
if (($file = file_check_upload('webfm_upload')) != FALSE) {
// Scale image uploads.
_webfm_image($file);
if (webfm_upload_validate($file, $err) === TRUE) {
// file has been put in temp and we have a valid file object
// Cache filepath as $_SESSION var for ajax confirm when name conflict
// positive response will swap fid and munged name
$check_file_exist = $dest . '/' . $file->filename;
if (is_file($check_file_exist)) {
if (webfm_get_file_record('', $check_file_exist)) {
$file->db_check = $db_check;
}
$file->dest = $dest;
$_SESSION['temp_upload'] = $file;
$json_data['file'] = $file->filename;
$json_data['html'] = webfm_reload_upload('webfm/upload', webfm_version_form($file->filename));
}
else {
if (file_move($file, $dest)) {
// file was moved to its final destination
if ($db_check == TRUE) {
//Insert file into database if under webfm_root
if (webfm_dbinsert_file($file, $err)) {
// file was inserted into the database
drupal_set_message(t('Upload Success'));
}
else {
file_delete($file->filepath);
drupal_set_message(t('Insertion into database fail'), error);
}
}
else {
// Uploaded to non-db-controlled area
drupal_set_message(t('Upload success'));
}
}
else {
drupal_set_message(t('file_move to %path failed', array(
'%path' => $dest,
)), error);
}
}
}
else {
drupal_set_message(t('file %s is not valid for upload', array(
'%s' => $file->filename,
)), error);
}
}
else {
drupal_set_message(t('file_check_upload() failed: Check your php configuration to ensure that "max_file_upload" is greater than the file size you are attempting to upload.'), error);
}
}
else {
drupal_set_message(t('Invalid upload path'), error);
}
if (!isset($json_data['html'])) {
$json_data['html'] = webfm_reload_upload('webfm/upload');
}
print drupal_to_js(array(
'status' => TRUE,
'data' => $json_data,
));
exit;
}