Created
May 16, 2015 13:04
-
-
Save nawawi/524e9d77a3dff57ef4b9 to your computer and use it in GitHub Desktop.
Check uploaded file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check uploaded file | |
* | |
* @param string $file file | |
* @param int $max_file_length Maximum file length | |
* @return bool Return TRUE if Ok, FALSE otherwise. | |
*/ | |
function _check_upload_filename($file, $max_file_length = 260) { | |
$valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; | |
$file_name = preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($file) ); | |
return ( strlen($file_name) == 0 || strlen($file_name) > $max_file_length ? false : true ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment