Within PHP, how can I make sure a directory as public read access from the web?
<p>I have a bunch of JavaScript files that I want to minify and then cache it to a file. This file is saved to a location I provide as argument.</p>

<p>How can I make sure that location has is accessible from the web?  </p>

<p>What I've tried so far:</p>

<pre><code>$test = array
(
    '/Users/www/htdocs/test/nhecos/cache/test.js',
    '/Users/www/foo.js'
);
$host = 'http://localhost/';

foreach($test as $t) {
    $url = str_replace($_SERVER['DOCUMENT_ROOT'], $host, $t, $count);
    $perms = substr(sprintf('%o', fileperms($t)), -4);
    $p = substr($perms, -1);

    if ($count &gt; 0 &amp;&amp; $p &gt;= 4) 
        print $url;
    else 
        throw new \Exception(sprintf("File %s not accessible from Web!", $t));
}
</code></pre>

<p>This works most of the times but fails if, for instance, that file is in a Virtual Host directory or in a linked folder. Is there any better way? </p>

<p><strong>NOTE: my problem is ensuring that</strong> </p>

<blockquote>
  <p>"The files I generate are in a location that is known to the web
  server and is mapped to a URL."</p>
</blockquote>
