diff options
author | Simon Rettberg | 2014-05-23 20:49:02 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-05-23 20:49:02 +0200 |
commit | fe6ac16498b05d0f0c8ed7fda394273815d3d6da (patch) | |
tree | cadf5f103ef3db7ba1b40d59d85937c998aad22f /inc/util.inc.php | |
parent | Server Setup page (diff) | |
download | slx-admin-fe6ac16498b05d0f0c8ed7fda394273815d3d6da.tar.gz slx-admin-fe6ac16498b05d0f0c8ed7fda394273815d3d6da.tar.xz slx-admin-fe6ac16498b05d0f0c8ed7fda394273815d3d6da.zip |
Stuff (WIP)
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r-- | inc/util.inc.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php index 4b974f6d..63680023 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -173,6 +173,49 @@ class Util } return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . $sz[$factor]; } + + public static function sanitizeFilename($name) + { + return preg_replace('/[^a-zA-Z0-9_\-]+/', '_', $name); + } + + /** + * Create human readable error description from a $_FILES[<..>]['error'] code + * + * @param int $code the code to turn into an error description + * @return string the error description + */ + public static function uploadErrorString($code) + { + switch ($code) { + case UPLOAD_ERR_INI_SIZE: + $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini"; + break; + case UPLOAD_ERR_FORM_SIZE: + $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"; + break; + case UPLOAD_ERR_PARTIAL: + $message = "The uploaded file was only partially uploaded"; + break; + case UPLOAD_ERR_NO_FILE: + $message = "No file was uploaded"; + break; + case UPLOAD_ERR_NO_TMP_DIR: + $message = "Missing a temporary folder"; + break; + case UPLOAD_ERR_CANT_WRITE: + $message = "Failed to write file to disk"; + break; + case UPLOAD_ERR_EXTENSION: + $message = "File upload stopped by extension"; + break; + + default: + $message = "Unknown upload error"; + break; + } + return $message; + } } |