escaping - PHP: escape filename as linux does -


i'm having troubles filenames upload users have process. when try access them, because of them have special characters, command used says file not found or similar.

i've used escapeshellcmd no sucess.

when use "tab" key in linux console (when have started type filename , want complete), bash escape filename correctly, , if use "escaped" filename, works.

i've tried this:

preg_replace("/[^a-za-z0-9\-\.\s]/", "\\\\$0", $filename) 

to escape except numbers, letters, - , spaces ... found file "test_1.jpg", command converts "test_1.jpg", , not work, since "_" not need converted.

i'm afraid there more "allowed" characters, question ... how can "clone" escape function of "tab" key in linux console bash ?

thank !

i use both file names , making urls out of blog post titles , like.

// lower , no spaces begin or end $path = strtolower(trim($path));  // adding - spaces , union characters $find = array(' ', '&', '\r\n', '\n', '+',','); $path = str_replace ($find, '-', $path);  //delete , replace rest of special chars $find = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'); $repl = array('', '-', ''); $path = preg_replace ($find, $repl, $path); 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -