title: Unable to read file in directory with file_get_contents - PHP
body: <p>I have a file present in a directory <code>content</code> that contains a file to read from. On my <code>MAMP</code> installation, <code>content/</code> is present in the webroot folder (<code>/Applications/MAMP/htdocs/testApp/content</code>). I am unable to read the file (test.txt) from the folder. The function I am using is:  </p>
  
  <pre><code>function getDataFromLibrary($tgt_url) {
  
          //header('Content-Type: text/html; charset=UTF-8');
          echo "inside get data from lib.";
          if(file_exists($tgt_url)) {
              echo "File does exist.";
              if(is_readable($tgt_url)) {
                  echo "file is readable.";
              } else {
                  echo "file is not readable.";
              }
          } else {
              echo "File does not exist.";
          }
          echo "tgt url = ".$tgt_url."the end.";
          $file_contents = file_get_contents(urlencode($tgt_url));
          if($file_contents === false) {
              echo "could not read file contents.";
          } else {
              echo "file contents read.";
          }
          echo "Target url=".var_dump($tgt_url)."again the end.";
          echo "File contents = ".$file_contents;
          //$file_contents_replaced = str_replace($file_contents, "\"", "\\\"");
          //echo $file_contents_replaced;
          //var_dump($file_contents);
          //return $tgt_url;
      }
  </code></pre>
  
  <p>and the output I get when <code>$tgt_url = content/test.txt</code> is:</p>
  
  <pre><code>inside get data from lib.File does exist.file is readable.tgt url = content/test.txtthe end.could not read file contents.string(33) "content/test.txt" Target url=again the end.File contents =  
  </code></pre>
  
  <p>The file does exist and is also readable. Where am I going wrong? </p>
  
  <p>Any help is most welcome.</p>
  
  <p>Edit:<br>
  I turned on the following errors in php.ini: 
  <code>display_errors = On</code>
  and in the script, I included the lines:  </p>
  
  <pre><code>error_reporting(E_ALL);
      ini_set('display_errors',1);
      ini_set('display_startup_errors',1);
      error_reporting(-1);  
  </code></pre>
  
  <p>The output is: </p>
  
  <pre><code>inside get data from lib.File does exist.file is readable.tgt url = content/test.txtthe end.
  Warning: file_get_contents(content%2Ftest.txt): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/testApp/index.php on line 323
  could not read file contents.string(33) "content/test.txt" Target url=again the end.File contents =
  </code></pre>