title: php file search issue - not returning full path to file
body: <p>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.</p>
  
  <p>Now let's say that i have the following files on my server:</p>
  
  <blockquote>
    <p>/folder/example file number one.zip 
    /folder/example file number two.zip
    /folder/example file number three.zip</p>
  </blockquote>
  
  <p>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 (/folder/example file number XXX.zip).</p>
  
  <p>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</p>
  
  <p>Can you help me to fix that ?</p>
  
  <pre><code>$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";
          $taillekb = filesize($downloadlink) / 1024;
          echo "&lt;br&gt;Size: $taillekb KB&lt;br&gt;";
      } else {
          echo "File not found";
      }
  
   }
  </code></pre>