Skip to content

Instantly share code, notes, and snippets.

@nawawi
Created May 16, 2015 13:04
Show Gist options
  • Save nawawi/524e9d77a3dff57ef4b9 to your computer and use it in GitHub Desktop.
Save nawawi/524e9d77a3dff57ef4b9 to your computer and use it in GitHub Desktop.
Check uploaded file
/**
* 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