gdfhghjdfghgfhf Posted July 1, 2013 Share Posted July 1, 2013 This script will search my server for files starting by a specific string, then return the download links. Search query is defined by "f" GET value. Now let's say that i have the following files on my server: /folder/example file number one.zip /folder/example file number two.zip /folder/example file number three.zip If i search for "example file" then the script will return 3 results BUT every download links will be "/folder/example file" instead of the FULL filename. This will also create a bug with the filesize() function at the end of the script, since filesize() will look for the size of "/folder/example file" instead of using the full filename Can you help me to fix that ? $request = $_GET['f']; $adr = $_SERVER['QUERY_STRING']; $decode = rawurldecode(substr($adr, 2)); echo "Searching for $decode"; // finding the file on the server $root = $_SERVER['DOCUMENT_ROOT']; $search = preg_quote(utf8_decode($decode)); 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; } $resultatss = rsearch($root, '/.*\/'.$search.'/'); foreach ($resultatss as $resultat) { $downloadlink = str_replace("$root/", "", $resultat); $pos = strrpos($downloadlink, '/') + 1; $encodedownloadlink = substr($downloadlink, 0, $pos) . rawurlencode(substr($downloadlink, $pos)); if (!empty($downloadlink)) { echo "download link = http://www.mydomain.com/$encodedownloadlink"; } else { echo "File not found"; } $taillekb = filesize($downloadlink) / 1024; echo "<br>Size: $taillekb KB<br>"; } Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/279769-file-search-issue/ Share on other sites More sharing options...
gdfhghjdfghgfhf Posted July 4, 2013 Author Share Posted July 4, 2013 bump Quote Link to comment https://forums.phpfreaks.com/topic/279769-file-search-issue/#findComment-1439369 Share on other sites More sharing options...
AbraCadaver Posted July 4, 2013 Share Posted July 4, 2013 Not positive but try: $files = new RegexIterator($ite, $pattern); Quote Link to comment https://forums.phpfreaks.com/topic/279769-file-search-issue/#findComment-1439446 Share on other sites More sharing options...
Barand Posted July 4, 2013 Share Posted July 4, 2013 You could try using realpath Quote Link to comment https://forums.phpfreaks.com/topic/279769-file-search-issue/#findComment-1439470 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted July 4, 2013 Author Share Posted July 4, 2013 (edited) @AbraCadaver: not working @Barand: the problem is that the script returns incomplete filenames. If i have a file called "test123456789.zip" on my server and i use the script to search for "test12345" it will return 1 match but the script will print "test12345" instead of printing "test123456789.zip" Not sure how i could use realpath() to get the full filename of "test12345" Edited July 4, 2013 by ungovernable Quote Link to comment https://forums.phpfreaks.com/topic/279769-file-search-issue/#findComment-1439476 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted July 11, 2013 Author Share Posted July 11, 2013 Still stuck with this problem... Quote Link to comment https://forums.phpfreaks.com/topic/279769-file-search-issue/#findComment-1440277 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.