php - jQuery File Upload - blueimp filenames with special characters -


some of users attach files names contain special characters problematic utility when downloading , uploading, single quotes, spaces, etc. seems should simple problem address since i'm "greenie" when coding use help.

i've tried modifying 'uploadhandler.php' functions manipulate file name no success. i'm not sure if need address @ input level on form or on upload...

my last attempt in trim_file_name() function:

protected function trim_file_name($name,         $type = null, $index = null, $content_range = null) {     // remove path information , dots around filename, prevent uploading     // different directories or replacing hidden system files.     // remove control characters , spaces (\x00..\x20) around filename:     $name = trim(basename(stripslashes($name)), ".\x00..\x20");     // use timestamp empty filenames:     if (!$name) {         $name = str_replace('.', '-', microtime(true));         $name = preg_replace('/[^a-za-z0-9\-]/', '', $name); <==== attempt     }     // add missing file extension known image types:     if (strpos($name, '.') === false &&         preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {         $name .= '.'.$matches[1];     }     return $name; } 

i use this. i'm frustrated.

thanks,

i use couple of functions have worked in production sanitise , clean file names, i'll put them below.

public static function cleanfilename($filename) {     $filename = htmlentities($filename, ent_quotes, 'utf-8');     $filename = preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', $filename);     $filename = html_entity_decode($filename, ent_quotes, 'utf-8');     $filename = preg_replace(array('~[^0-9a-z]~i', '~[ -]+~'), ' ', $filename);     return trim($filename, ' -'); }  public static function sanitizefilename($filename) {     $dangerous_characters = array(" ", '"', "'", "&", "/", "\\", "?", "#");     return str_replace($dangerous_characters, '_', $filename); } 

so once you've copied both functions uploadhandler class, modified trim_file_name function this:

protected function trim_file_name($name,     $type = null, $index = null, $content_range = null) { // remove path information , dots around filename, prevent uploading // different directories or replacing hidden system files. // remove control characters , spaces (\x00..\x20) around filename: $name = trim(basename(stripslashes($name)), ".\x00..\x20");  // use timestamp empty filenames: if (!$name) {     $name = str_replace('.', '-', microtime(true)); } // add missing file extension known image types: if (strpos($name, '.') === false &&     preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {     $name .= '.'.$matches[1]; } // call sanitize file name function $name = uploadhandler::sanitizefilename($name); // call clean file name function $name = uploadhandler::cleanfilename($name); return $name; } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -