From f79debe0963b82323e6032e0c4ad2d4aff001c47 Mon Sep 17 00:00:00 2001 From: Piotr KUCHARSKI Date: Mon, 24 Nov 2014 20:59:30 +0100 Subject: [PATCH] simplify sanitize() function --- createthumb.php | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/createthumb.php b/createthumb.php index a9c3ee6..28b40f8 100644 --- a/createthumb.php +++ b/createthumb.php @@ -60,29 +60,9 @@ function flipHorizontal(&$img) { } } -function str_split_php4( $text, $split = 1 ) { - // place each character of the string into and array - $array = array(); - for ( $i=0; $i < strlen( $text ); ) - { - $key = NULL; - for ( $j = 0; $j < $split; $j++, $i++ ) - { - $key .= $text[$i]; - } - array_push( $array, $key ); - } - return $array; -} - -function sanitize($name) -{ - // Sanitize image filename (taken from http://iamcam.wordpress.com/2007/03/20/clean-file-names-using-php-preg_replace/ ) - $fname=$name; - $replace="_"; - $pattern="/([[:alnum:]_\.-]*)/"; - $fname=str_replace(str_split_php4(preg_replace($pattern,$replace,$fname)),$replace,$fname); - return $fname; +function sanitize($name) { +// note: this allows for collisions + return preg_replace("/[^[:alnum:]_.-]/", "_", $name); } // Make sure the "thumbs" directory exists.