From 598e19130bc39b0c61a0d677b98150c5a131f1a8 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Thu, 6 Aug 2015 12:27:30 -0400 Subject: [PATCH] #275 Add attachments.inc.php to source control --- .gitignore | 1 - inc/attachments.inc.php | 133 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 inc/attachments.inc.php diff --git a/.gitignore b/.gitignore index 02bb49b7..e4ef0e68 100644 --- a/.gitignore +++ b/.gitignore @@ -146,7 +146,6 @@ img/unlock.png img/vertical.jpg img/view.png inc/assignment_search.inc.php -inc/attachments.inc.php inc/calendar/img/cal.gif inc/calendar/img/next_mon.gif inc/calendar/img/next_year.gif diff --git a/inc/attachments.inc.php b/inc/attachments.inc.php new file mode 100644 index 00000000..71521905 --- /dev/null +++ b/inc/attachments.inc.php @@ -0,0 +1,133 @@ + $hesk_settings['attachments']['max_size']) + { + return hesk_fileError(sprintf($hesklang['file_too_large'], $file_realname)); + } + else + { + $file_size = $_FILES['attachment']['size'][$i]; + } + + /* Generate a random file name */ + $useChars='AEUYBDGHJLMNPQRSTVWXZ123456789'; + $tmp = uniqid(); + for($j=1;$j<10;$j++) + { + $tmp .= $useChars{mt_rand(0,29)}; + } + + if (defined('KB')) + { + $file_name = substr(md5($tmp . $file_realname), 0, 200) . $ext; + } + else + { + $file_name = substr($trackingID . '_' . md5($tmp . $file_realname), 0, 200) . $ext; + } + + // Does the temporary file exist? If not, probably server-side configuration limits have been reached + // Uncomment this for debugging purposes + /* + if ( ! file_exists($_FILES['attachment']['tmp_name'][$i]) ) + { + return hesk_fileError($hesklang['fnuscphp']); + } + */ + + /* If upload was successful let's create the headers */ + if ( ! move_uploaded_file($_FILES['attachment']['tmp_name'][$i], dirname(dirname(__FILE__)).'/'.$hesk_settings['attach_dir'].'/'.$file_name)) + { + return hesk_fileError($hesklang['cannot_move_tmp']); + } + + $info = array( + 'saved_name'=> $file_name, + 'real_name' => $file_realname, + 'size' => $file_size + ); + + return $info; +} // End hesk_uploadFile() + + +function hesk_fileError($error) +{ + global $hesk_settings, $hesklang, $trackingID; + global $hesk_error_buffer; + + $hesk_error_buffer['attachments'] = $error; + + return false; +} // End hesk_fileError() + + +function hesk_removeAttachments($attachments) +{ + global $hesk_settings, $hesklang; + + $hesk_settings['server_path'] = dirname(dirname(__FILE__)).'/'.$hesk_settings['attach_dir'].'/'; + + foreach ($attachments as $myatt) + { + hesk_unlink($hesk_settings['server_path'].$myatt['saved_name']); + } + + return true; +} // End hesk_removeAttachments()