Merge pull request #75 from bifek/sanitize

simplify sanitize() function
This commit is contained in:
Tom.C. 2014-11-26 18:24:27 +01:00
commit a57b081377

View file

@ -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.