gdfhghjdfghgfhf Posted July 27, 2013 Share Posted July 27, 2013 I have a script that will search for a file inside all directories of my server, then return the full path to the file. The search query comes encoded in base64.The script works perfectly when searching a file without accents. But as soon as i search for something with accents, it won't work.Here is my file structure: /var/www/clients/client2/web1/web/dl/pp/6250/Ya Basta! - 2002 - Lucha Y Fiesta.zip/var/www/clients/client2/web1/web/dl/pp/6250/La Souris Déglinguée - 1988 - Quartier Libre.zip When searching for the first file (WWEgQmFzdGEhIC0gMjAwMiAtIEx1Y2hhIFkgRmllc3RhLnppcA==) it will return the correct path. But when searching for the second file with accents (TGEgU291cmlzIETpZ2xpbmd16WUgLSAxOTg4IC0gUXVhcnRpZXIgTGlicmUuemlw) it will not return any result even if the file existsHere's the script: header("Content-type: text/html; charset=utf-8"); // $encodedquery = "WWEgQmFzdGEhIC0gMjAwMiAtIEx1Y2hhIFkgRmllc3RhLnppcA=="; // query without accent = WORKS ! $encodedquery = "TGEgU291cmlzIETpZ2xpbmd16WUgLSAxOTg4IC0gUXVhcnRpZXIgTGlicmUuemlw" // query with accents = DOESNT WORKS $decode = utf8_encode(base64_decode($encodedquery); $search = preg_quote($decode); echo "searching for \"$search\" ...."; function rsearch($folder, $pattern) { $dir = new RecursiveDirectoryIterator($folder); $ite = new RecursiveIteratorIterator($dir); $files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH); $fileList = array(); foreach($files as $file) { $fileList = array_merge($fileList, $file); } return $fileList; } $root = $_SERVER['DOCUMENT_ROOT']; $resultatss = rsearch($root, '/.*\/'.$search.'/'); foreach ($resultatss as $resultat) { echo "<br>FOUND FILE = $resultat"; } Quote Link to comment https://forums.phpfreaks.com/topic/280579-regexiterator-recursive-iterator-cant-search-file-with-accents/ Share on other sites More sharing options...
jazzman1 Posted July 27, 2013 Share Posted July 27, 2013 Hey ungovernable, just use openssl instead utf8_encode to encode and after to decode the string of the file. So, here is a simple test that I made it for you: #!/bin/bash openssl enc -base64 <<< 'La Souris Déglinguée - 1988 - Quartier Libre.zip' Result: TGEgU291cmlzIETDqWdsaW5ndcOpZSAtIDE5ODggLSBRdWFydGllciBMaWJyZS56aXAK # decode the string openssl enc -base64 -d <<< 'TGEgU291cmlzIETDqWdsaW5ndcOpZSAtIDE5ODggLSBRdWFydGllciBMaWJyZS56 aXAK' Result: La Souris Déglinguée - 1988 - Quartier Libre.zip So, do you know how to run a bash command(s) inside the php script? Quote Link to comment https://forums.phpfreaks.com/topic/280579-regexiterator-recursive-iterator-cant-search-file-with-accents/#findComment-1442454 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted July 27, 2013 Author Share Posted July 27, 2013 So, do you know how to run a bash command(s) inside the php script? no :/ Quote Link to comment https://forums.phpfreaks.com/topic/280579-regexiterator-recursive-iterator-cant-search-file-with-accents/#findComment-1442457 Share on other sites More sharing options...
jazzman1 Posted July 28, 2013 Share Posted July 28, 2013 Ah, I see. I will try to give you an example later Quote Link to comment https://forums.phpfreaks.com/topic/280579-regexiterator-recursive-iterator-cant-search-file-with-accents/#findComment-1442459 Share on other sites More sharing options...
jazzman1 Posted July 28, 2013 Share Posted July 28, 2013 Bash in PHP make me start to sweat nervously Run that script onto your web server and tell me what result you get. <?php $str = 'La Souris Déglinguée - 1988 - Quartier Libre.zip'; $enc = "openssl enc -base64 <<< '$str'"; $exc = shell_exec($enc); $dec = "openssl enc -base64 -d <<< '$exc'"; echo shell_exec($dec); Quote Link to comment https://forums.phpfreaks.com/topic/280579-regexiterator-recursive-iterator-cant-search-file-with-accents/#findComment-1442464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.