title: "No such file or directory" when opening file with scandir in PHP
body: <p>I want to read the file with the longest file name in a folder called "json".</p>
  
  <p>This is my PHP for that: (inside file "open.php")</p>
  
  <pre><code>&lt;?php
  // Tell PHP that we're using UTF-8 strings until the end of the script
  mb_internal_encoding("UTF-8");
  // Tell PHP that we'll be outputting UTF-8 to the browser
  mb_http_output("UTF-8");
  
  $files = scandir( __DIR__ . '/json', SCANDIR_SORT_DESCENDING);
  $newest_file = $files[0];
  readfile($newest_file);
  //$output = file_get_contents($newest_file);
  //echo json_encode($output, JSON_HEX_TAG); 
  ?&gt;
  </code></pre>
  
  <p>The "json" folder is in the same directory as "open.php". When I run this on my server, I get as a response <code>false</code> (or a HTTP 500 error). </p>
  
  <p>When I run this on XAMPP, I get: <code>Warning: readfile(thisone.json): failed to open stream: No such file or directory in C:\xampp\htdocs\test\open.php on line 15</code>.<br>
  I don't think it's an issue with permissions since I'm on Win 7. I checked both folder and file permissions and all users can "read".</p>
  
  <p><strong>Question</strong>: Why is PHP failing to open the file? It correctly finds the file I want, but right afterwards tells me there is "no such file".</p>
  
  <hr>
  
  <p><em>UPDATE:</em><br>
  Running the following code:</p>
  
  <pre><code>// Tell PHP that we're using UTF-8 strings until the end of the script
  mb_internal_encoding("UTF-8");
  // Tell PHP that we'll be outputting UTF-8 to the browser
  mb_http_output("UTF-8");
  
  $files = scandir( __DIR__ . '\\json', SCANDIR_SORT_DESCENDING);
  print_r($files);
  $newest_file = $files[0];
  print_r($newest_file);
  readfile('/json/'.$newest_file); // corrected this, as @Jeff pointed out
  </code></pre>
  
  <p>I get as output:</p>
  
  <pre><code>Array ( [0] =&gt; thisone.json [1] =&gt; .. [2] =&gt; . ) thisone.json
  Warning: readfile(/json/thisone.json): failed to open stream: No such file or directory in C:\xampp\htdocs\test\open.php on line 18
  </code></pre>
  
  <p><hr>
  Related SO question: <a href="https://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory/36577021#36577021">PHP - Failed to open stream : No such file or directory</a></p>