title: Calling PHP function with ajax to read file
body: <p>I am taking file input from input type file and calling a javascript function on onchange event like below:</p>
  
  <pre><code>&lt;input type="file" onchange="readTheFile(this)"&gt;
  </code></pre>
  
  <p>The javascript function is calling a php file containing another PHP function. The javascrit function is:</p>
  
  <pre><code>function readTheFile(file){
  $.ajax( 
             {
                 url: 'readFile.php',
                 type: 'GET',
                 data: 'fileLoc= '+file,
                 success: function(output) 
                 {
                     document.getElementById("content").innerHTML = output ;
  
                 }
              }
          ); 
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I am always getting the error:</p>
  
  <pre><code>Warning: fopen( [object HTMLInputElement]) [function.fopen]: failed to open stream: No           such file or directory in D:\xampp\htdocs\sha\readFile.php on line 3
  Unable to open file!
  </code></pre>
  
  <p>content of readFile.php is:</p>
  
  <pre><code>&lt;?php
  function readFiles($fileLoc){
  $file = fopen($fileLoc, "r") or exit("Unable to open file!");
  while(!feof($file)) {
  echo fgets($file);
  }
  fclose($file);
  }
  
  if(isset($_GET['fileLoc'])){
  echo readFiles($_GET['fileLoc']);
  }
  ?&gt;
  </code></pre>