title: Search and Download file from a source directory using html form and php
body: <p>I have files like pdf in a directory and i have created a search form where in the user will input the filecode and it will search the source directory if it matches a filename it will allow the user to download the file, if not it will show "No Results" Here's what i did, but I am not sure what code should I use to download a file from my source directory, I just saw the code for downloading a file somewhere and substitute the source file with the variable i use when a user search </p>
  
  <pre><code>&lt;html&gt;
            &lt;head&gt;
              &lt;title&gt;Search  Contacts&lt;/title&gt;
            &lt;/head&gt;
            &lt;body&gt;
  
              &lt;h3&gt;Search Client File&lt;/h3&gt;
              &lt;form  method="post" action="#"  id="searchform"&gt;
                Type the File Code:&lt;br&gt;&lt;br&gt;
                    &lt;input  type="text" name="fcode"&gt;
              &lt;br&gt;
        &lt;input  type="submit" name="submit" value="Search"&gt;
              &lt;/form&gt;
  
  &lt;?php
  $filecode=$_POST["fcode"];
       if (!empty($filecode))
       {
   $ch = curl_init();
  $source = "/sdir/$filecode.pdf";
  curl_setopt($ch, CURLOPT_URL, $source);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $data = curl_exec ($ch);
  curl_close ($ch);
  
  $destination = "/tdir/afile.pdf";
  $file = fopen($destination, "w+");
  fputs($file, $data);
  fclose($file);
       }
       else
       {
         echo "No Results";
       }
  
          ?&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>