* @requires App.inc.php
* @version 1.3
*/
// Message Types.
define('UPLOAD_MSG_ERR', MSG_ERR);
define('UPLOAD_MSG_ERROR', MSG_ERROR);
define('UPLOAD_MSG_WARNING', MSG_WARNING);
define('UPLOAD_MSG_NOTICE', MSG_NOTICE);
define('UPLOAD_MSG_SUCCESS', MSG_SUCCESS);
define('UPLOAD_MSG_ALL', MSG_SUCCESS + MSG_NOTICE + MSG_WARNING + MSG_ERROR);
require_once dirname(__FILE__) . '/App.inc.php';
class Upload {
// General object parameters.
var $_params = array(
// Which messages do we pass to raiseMsg?
'display_messages' => UPLOAD_MSG_ALL,
// Existing files will be overwritten when there is a name conflict?
'allow_overwriting' => false,
// The filesystem path to the final upload directory.
'upload_path' => null,
// The file permissions of the uploaded files. Remember, files will be owned by the web server user.
'dest_file_perms' => 0600,
// Require file to have one of the following file name extentions.
'valid_file_extensions' => array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'txt', 'text', 'html', 'htm'),
);
// Array of files with errors.
var $errors = array();
// Array of file name extensions and corresponding mime-types.
var $mime_extension_map = array( 'ez' => 'application/andrew-inset', 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'doc' => 'application/msword', 'bin' => 'application/octet-stream', 'class' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'dms' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', 'so' => 'application/octet-stream', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'ps' => 'application/postscript', 'eps' => 'application/postscript', 'ai' => 'application/postscript', 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'stc' => 'application/vnd.sun.xml.calc.template', 'sxc' => 'application/vnd.sun.xml.calc', 'std' => 'application/vnd.sun.xml.draw.template', 'sxd' => 'application/vnd.sun.xml.draw', 'sti' => 'application/vnd.sun.xml.impress.template', 'sxi' => 'application/vnd.sun.xml.impress', 'sxm' => 'application/vnd.sun.xml.math', 'sxg' => 'application/vnd.sun.xml.writer.global', 'stw' => 'application/vnd.sun.xml.writer.template', 'sxw' => 'application/vnd.sun.xml.writer', 'vsd' => 'application/vnd.visio', 'wbxml' => 'application/vnd.wap.wbxml', 'wmlc' => 'application/vnd.wap.wmlc', 'wmlsc' => 'application/vnd.wap.wmlscriptc', 'bcpio' => 'application/x-bcpio', 'vcd' => 'application/x-cdlink', 'pgn' => 'application/x-chess-pgn', 'Z' => 'application/x-compress', 'cpio' => 'application/x-cpio', 'csh' => 'application/x-csh', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'spl' => 'application/x-futuresplash', 'gtar' => 'application/x-gtar', 'tgz' => 'application/x-gtar', 'gz' => 'application/x-gzip', 'hdf' => 'application/x-hdf', 'php3' => 'application/x-httpd-php3', 'php' => 'application/x-httpd-php', 'js' => 'application/x-javascript', 'skd' => 'application/x-koan', 'skm' => 'application/x-koan', 'skp' => 'application/x-koan', 'skt' => 'application/x-koan', 'latex' => 'application/x-latex', 'wmd' => 'application/x-ms-wmd', 'wmz' => 'application/x-ms-wmz', 'cdf' => 'application/x-netcdf', 'nc' => 'application/x-netcdf', 'pl' => 'application/x-perl', 'pm' => 'application/x-perl', 'shar' => 'application/x-shar', 'swf' => 'application/x-shockwave-flash', 'sh' => 'application/x-sh', 'sit' => 'application/x-stuffit', 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', 'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', 'tex' => 'application/x-tex', 'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'ms' => 'application/x-troff-ms', 'roff' => 'application/x-troff', 't' => 'application/x-troff', 'tr' => 'application/x-troff', 'ustar' => 'application/x-ustar', 'src' => 'application/x-wais-source', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', 'xml' => 'application/xml', 'zip' => 'application/zip', 'au' => 'audio/basic', 'snd' => 'audio/basic', 'kar' => 'audio/midi', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mp3' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'mpga' => 'audio/mpeg', 'aiff' => 'audio/x-aiff', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'm3u' => 'audio/x-mpegurl', 'wax' => 'audio/x-ms-wax', 'wma' => 'audio/x-ms-wma', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'ra' => 'audio/x-realaudio', 'wav' => 'audio/x-wav', 'pdb' => 'chemical/x-pdb', 'xyz' => 'chemical/x-xyz', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'ief' => 'image/ief', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'wbmp' => 'image/vnd.wap.wbmp', 'ras' => 'image/x-cmu-raster', 'pnm' => 'image/x-portable-anymap', 'pbm' => 'image/x-portable-bitmap', 'pgm' => 'image/x-portable-graymap', 'ppm' => 'image/x-portable-pixmap', 'rgb' => 'image/x-rgb', 'xbm' => 'image/x-xbitmap', 'xpm' => 'image/x-xpixmap', 'xwd' => 'image/x-xwindowdump', 'iges' => 'model/iges', 'igs' => 'model/iges', 'mesh' => 'model/mesh', 'msh' => 'model/mesh', 'silo' => 'model/mesh', 'vrml' => 'model/vrml', 'wrl' => 'model/vrml', 'ics' => 'text/calendar', 'ifb' => 'text/calendar', 'vcs' => 'text/calendar', 'vfb' => 'text/calendar', 'css' => 'text/css', 'diff' => 'text/diff', 'patch' => 'text/diff', 'html' => 'text/html', 'htm' => 'text/html', 'shtml' => 'text/html', 'txt' => 'text/plain', 'asc' => 'text/plain', 'log' => 'text/plain', 'po' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'sgm' => 'text/sgml', 'sgml' => 'text/sgml', 'tsv' => 'text/tab-separated-values', 'wmls' => 'text/vnd.wap.wmlscript', 'wml' => 'text/vnd.wap.wml', 'etx' => 'text/x-setext', 'vcf' => 'text/x-vcard', 'xsl' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mov' => 'video/quicktime', 'qt' => 'video/quicktime', 'mxu' => 'video/vnd.mpegurl', 'asf' => 'video/x-ms-asf', 'asx' => 'video/x-ms-asf', 'wmv' => 'video/x-ms-wmv', 'wm' => 'video/x-ms-wm', 'wmx' => 'video/x-ms-wmx', 'wvx' => 'video/x-ms-wvx', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie', 'ice' => 'x-conference/x-cooltalk', );
/**
* Set (or overwrite existing) parameters by passing an array of new parameters.
*
* @access public
* @param array $params Array of parameters (key => val pairs).
*/
function setParam($params)
{
if (isset($params) && is_array($params)) {
// Enforce valid upload_path parameter.
if (isset($params['upload_path'])) {
// $params['upload_path'] = realpath($params['upload_path']);
$params['upload_path'] = $params['upload_path'];
// Must be directory.
if (!is_dir($params['upload_path'])) {
App::logMsg(sprintf('Upload directory invalid: %s', $params['upload_path']), LOG_ERR, __FILE__, __LINE__);
trigger_error(sprintf('Upload directory invalid: %s', $params['upload_path']), E_USER_ERROR);
}
// Must be writable.
if (!is_writable($params['upload_path'])) {
App::logMsg(sprintf('Upload directory not writable: %s', $params['upload_path']), LOG_ERR, __FILE__, __LINE__);
trigger_error(sprintf('Upload directory not writable: %s', $params['upload_path']), E_USER_ERROR);
}
}
// Merge new parameters with old overriding only those passed.
$this->_params = array_merge($this->_params, $params);
} else {
App::logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
}
}
/**
* Return the value of a parameter, if it exists.
*
* @access public
* @param string $param Which parameter to return.
* @return mixed Configured parameter value.
*/
function getParam($param)
{
if (isset($this->_params[$param])) {
return $this->_params[$param];
} else {
App::logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
return null;
}
}
/**
* Process uploaded files. Processes files existing within the specified $_FILES['form_name'] array.
* It tests for errors, cleans the filename, optionally sets custom file names. It will process
* multiple files automatically if the file form element is an array ().
*
* @access public
* @param string $form_name The name of the form to process.
* @param string $custom_file_name The new name of the file. An array of filename in the case of multiple files.
* @return mixed Returns FALSE if a major error occured preventing any file uploads.
* Returns an empty array if any minor errors occured or no files were found.
* Returns a multidimentional array of filenames, sizes and extentions, if one-or-more files succeeded uploading.
* Note: this last option presents a problem in the case of when some files uploaded successfully, and some failed.
* In this case it is necessary to check the Upload::anyErrors method to discover if any did fail.
*/
function process($form_name, $custom_file_name=null)
{
// Ensure we have a upload directory.
if (!$this->getParam('upload_path')) {
App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
$this->raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
return false;
}
// Ensure the file form element specified actually exists.
if (!isset($_FILES[$form_name])) {
App::logMsg(sprintf(_("Form element %s does not exist."), $form_name), LOG_ERR, __FILE__, __LINE__);
$this->raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
return false;
}
if (is_array($_FILES[$form_name]['name'])) {
$files = $_FILES[$form_name];
} else {
// Convert variables to single-cell array so it will loop.
$files = array(
'name' => array($_FILES[$form_name]['name']),
'type' => array($_FILES[$form_name]['type']),
'tmp_name' => array($_FILES[$form_name]['tmp_name']),
'error' => array($_FILES[$form_name]['error']),
'size' => array($_FILES[$form_name]['size']),
);
}
// To keep this script running even if user tries to stop browser.
ignore_user_abort(true);
ini_set('max_execution_time', 300);
ini_set('max_input_time', 300);
$new_file_names = array();
$num = sizeof($files['name']);
for ($i=0; $i<$num; $i++) {
$file_path_name = '';
if ('' == trim($files['name'][$i])) {
// User may not have attached a file.
continue;
}
// Determine final file name.
if ($num == 1) {
// Single upload.
if (isset($custom_file_name) && '' != $custom_file_name) {
// Valid custom file name.
$file_name = $custom_file_name;
$this->raiseMsg(sprintf(_("The file %s has been renamed to %s."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
App::logMsg(sprintf('Using custom file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
} else {
// Invalid custom file name provided. Use uploaded file name.
$file_name = $files['name'][$i];
App::logMsg(sprintf('Using uploaded file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
}
} else {
// Multiple upload. Final file names must be array.
if (isset($custom_file_name) && is_array($custom_file_name) && is_array($custom_file_name[$i]) && '' != $custom_file_name[$i]) {
// Valid custom file name.
$file_name = $custom_file_name[$i];
$this->raiseMsg(sprintf(_("The file %s has been renamed to %s."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
App::logMsg(sprintf('Using custom file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
} else {
// Invalid custom file name provided. Use uploaded file name.
$file_name = $files['name'][$i];
App::logMsg(sprintf('Using uploaded file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
}
}
// Clean the file name of bad characters.
$file_name = $this->cleanFileName($file_name);
// If the file name has no extension, use the mime-type extension.
if (!preg_match('/\.[^.]{1,5}$/', $file_name) && function_exists('mime_content_type')) {
if ($ext = array_search(mime_content_type($files['tmp_name'][$i]), $this->mime_extension_map)) {
$file_name .= ".$ext";
}
}
// Set the path and file name.
$file_path_name = $this->getParam('upload_path') . '/' . $file_name;
// Check The php upload error messages.
if (UPLOAD_ERR_INI_SIZE === $files['error'][$i]) {
if ($this->getParam('display_messages')) {
$this->raiseMsg(sprintf(_("The file %s failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, ini_get('upload_max_filesize')), MSG_ERR, __FILE__, __LINE__);
}
App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_INI_SIZE (currently %s)."), $files['error'][$i], $file_name, ini_get('upload_max_filesize')), LOG_ERR, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
if (UPLOAD_ERR_FORM_SIZE === $files['error'][$i]) {
$this->raiseMsg(sprintf(_("The file %s failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, $_POST['MAX_FILE_SIZE']), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_FORM_SIZE (currently %s)."), $files['error'][$i], $file_name, $_POST['MAX_FILE_SIZE']), LOG_ERR, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
if (UPLOAD_ERR_PARTIAL === $files['error'][$i]) {
$this->raiseMsg(sprintf(_("The file %s failed uploading: it was only partially uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_PARTIAL."), $files['error'][$i], $file_name), LOG_ERR, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
if (UPLOAD_ERR_NO_FILE === $files['error'][$i]) {
$this->raiseMsg(sprintf(_("The file %s failed uploading: no file was uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_NO_FILE."), $files['error'][$i], $file_name), LOG_ERR, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
if (UPLOAD_ERR_NO_TMP_DIR === $files['error'][$i]) {
$this->raiseMsg(sprintf(_("The file %s failed uploading: temporary upload directory missing."), $file_name), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_NO_TMP_DIR."), $files['error'][$i], $file_name), LOG_ERR, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
// Check to be sure it's an uploaded file.
if (!is_uploaded_file($files['tmp_name'][$i])) {
$this->raiseMsg(sprintf(_("The file %s failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("The file %s failed is_uploaded_file."), $file_name), LOG_ERR, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
// Check to be sure the file is not empty.
if ($files['size'][$i] < 1) {
$this->raiseMsg(sprintf(_("The file %s failed uploading: it contains zero bytes."), $file_name), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("The uploaded file %s contains zero bytes."), $file_name), LOG_ERR, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
// Check to be sure the file has a valid file name extension.
if (!in_array(strtolower($this->getFilenameExtension($file_name)), $this->getParam('valid_file_extensions'))) {
$this->raiseMsg(sprintf(_("The file %s failed uploading: it is an unrecognized type. Files must have one of the following file name extensions: %s."), $file_name, join(', ', $this->getParam('valid_file_extensions'))), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("The uploaded file %s has an unrecognized file name extension."), $file_name), LOG_WARNING, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
// Check to be sure the file has a unique file name.
if (!$this->getParam('allow_overwriting') && $this->exists($file_name)) {
$this->raiseMsg(sprintf(_("The file %s failed uploading: a file with that name already exists."), $file_name), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("The uploaded file %s doesn't have a unique filename."), $file_name), LOG_WARNING, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
// Move the file to the final place.
if (move_uploaded_file($files['tmp_name'][$i], $file_path_name)) {
chmod($file_path_name, $this->getParam('dest_file_perms'));
App::logMsg(sprintf('File uploaded: %s', $file_path_name), LOG_INFO, __FILE__, __LINE__);
$this->raiseMsg(sprintf(_("The file %s uploaded successfully."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
if (!isset($custom_file_name) && $files['name'][$i] != $file_name) {
// Notify user if uploaded file name was modified (unless a custom file name will be used anyways).
$this->raiseMsg(sprintf(_("The file %s was renamed to %s."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
}
$new_file_names[] = array(
'name' => $file_name,
'mime' => $files['type'][$i],
'size' => filesize($file_path_name),
'extension' => $this->getFilenameExtension($file_name),
'original_index' => $i,
'original_name' => $files['name'][$i],
);
continue;
} else {
$this->raiseMsg(sprintf(_("The file %s failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("Moving file failed: %s -> %s"), $files['tmp_name'][$i], $file_path_name), LOG_ALERT, __FILE__, __LINE__);
$this->errors[] = $file_name;
continue;
}
}
// Return names of files uploaded (or empty array when none processed).
return $new_file_names;
}
/**
* Remove file within upload path.
*
* @access public
* @param string $file_name A name of a file.
* @param bool $use_glob Set true to use glob to find the filename (using $file_name as a pattern)
* @return bool Success of operation.
*/
function deleteFile($file_name, $use_glob=false)
{
// Ensure we have a upload directory.
if (!$this->getParam('upload_path')) {
App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
return false;
}
$file_path_name = $this->getParam('upload_path') . '/' . ($use_glob ? $this->getFilenameGlob($file_name) : $file_name);
if (!is_file($file_path_name)) {
App::logMsg(sprintf(_("Error deleting nonexistent file: %s"), $file_path_name), LOG_ERR, __FILE__, __LINE__);
return false;
} else if (unlink($file_path_name)) {
App::logMsg(sprintf('Deleted file: %s', $file_path_name), LOG_INFO, __FILE__, __LINE__);
} else {
$this->raiseMsg(sprintf(_("The file %s could not be deleted."), $file_name), MSG_ERR, __FILE__, __LINE__);
App::logMsg(sprintf(_("Failed deleting file: %s"), $file_path_name), LOG_ERR, __FILE__, __LINE__);
return false;
}
}
/**
* Renames a file within the upload path.
*
* @access public
* @param string $old_name The currently existing file name.
* @param string $new_name The new name for this file.
* @return bool Success of operation.
*/
function moveFile($old_name, $new_name)
{
// Ensure we have an upload directory.
if (!$this->getParam('upload_path')) {
App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
return false;
}
$old_file_path_name = $this->getParam('upload_path') . '/' . $old_name;
$new_file_path_name = $this->getParam('upload_path') . '/' . $new_name;
if (file_exists($old_file_path_name)) {
if (rename($old_file_path_name, $new_file_path_name)) {
$this->raiseMsg(sprintf(_("The file %s has been renamed to %s."), basename($old_file_path_name), basename($new_file_path_name)), MSG_NOTICE, __FILE__, __LINE__);
App::logMsg(sprintf('File renamed from %s to %s', $old_file_path_name, $new_file_path_name), LOG_DEBUG, __FILE__, __LINE__);
} else {
$this->raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_WARNING, __FILE__, __LINE__);
App::logMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), LOG_WARNING, __FILE__, __LINE__);
return false;
}
} else {
$this->raiseMsg(sprintf(_("Couldn't rename nonexistent file %s."), $old_name), MSG_WARNING, __FILE__, __LINE__);
App::logMsg(sprintf(_("Error renaming nonexistent file: %s"), $old_file_path_name), LOG_WARNING, __FILE__, __LINE__);
return false;
}
}
/**
* Tests if a file exists within the current upload_path.
*
* @access public
* @param string $file_name A name of a file.
* @return bool Existence of file.
*/
function exists($file_name)
{
// Ensure we have a upload directory.
if (!$this->getParam('upload_path')) {
App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
return false;
}
return file_exists($this->getParam('upload_path') . '/' . $file_name);
}
/**
* Get filename by glob pattern. Searches a directory for an image that matches the
* specified glob pattern and returns the filename of the first file found.
*
* @access public
* @param string $pattern Pattern to match filename.
* @return string filename on success, empty string on failure.
* @author Quinn Comendant
* @since 15 Nov 2005 20:55:22
*/
function getFilenameGlob($pattern)
{
$file_list = glob(sprintf('%s/%s', $this->getParam('upload_path'), $pattern));
if (isset($file_list[0])) {
return basename($file_list[0]);
} else {
return '';
}
}
/**
* Returns an array of file names that failed uploading.
*
* @access public
* @return array List of file names.
*/
function getErrors()
{
return $this->errors;
}
/**
* Determintes if any errors occured while calling the Upload::process method.
*
* @access public
*/
function anyErrors()
{
return sizeof($this->errors) > 0;
}
/**
* Removes unsafe characters from file name.
*
* @access public
* @param string $file_name A name of a file.
* @return string The same name, but cleaned.
*/
function cleanFileName($file_name)
{
$bad = 'áéíóúàèìòùäëïöüÁÉÍÓÚÀÈÌÒÙÄËÏÖÜâêîôûÂÊÎÔÛñçÇ@';
$good = 'aeiouaeiouaeiouAEIOUAEIOUAEIOUaeiouAEIOUncCa';
$file_name = trim($file_name);
$file_name = strtr($file_name, $bad, $good);
$file_name = preg_replace('/[^-\w.,~_=+()]/i', '_', $file_name);
$file_name = substr($file_name, 0, 250);
return $file_name;
}
/**
* Returns the extention of a file name, or an empty string if non exists.
*
* @access public
* @param string $file_name A name of a file, with extention after a dot.
* @return string The value found after the dot
*/
function getFilenameExtension($file_name)
{
preg_match('/.*?\.(\w+)$/i', trim($file_name), $ext);
return isset($ext[1]) ? $ext[1] : '';
}
/**
* An alias for App::raiseMsg that only sends messages configured by display_messages.
*
* @access public
*
* @param string $message The text description of the message.
* @param int $type The type of message: MSG_NOTICE,
* MSG_SUCCESS, MSG_WARNING, or MSG_ERR.
* @param string $file __FILE__.
* @param string $line __LINE__.
*/
function raiseMsg($message, $type, $file, $line)
{
if ($this->getParam('display_messages') === true || (is_int($this->getParam('display_messages')) && $this->getParam('display_messages') >= $type)) {
App::raiseMsg($message, $type, $file, $line);
}
}
}
?>