Jump to content

Can I allow PHP to read file/folder attributes without giving full access?


msing

Recommended Posts

Hi I've got some PHP code in my nav bar (which is included in every site page) that recursively reads file/folder modification times in the entire site to find the most recently modified file time, and displays that.

 

I recently made some pages that are password protected and now that code fails and stops the the rest of the page from processing. So it's trying to read all of the file mod times, but apparently gets stuck on the password protected directories and dies.

 

So short of removing the protection on these directories, is there a way to allow this code (apparently executing as the anonymous user) to read the appropriate file/folder attribute information without giving read access to anonymous users?

Nope doesn't look like it. There's an option for ignoring errors.

 

I tried that in the hopes that the page would at least finish loading when the function call failed, but no dice either.

 

I should note that I didn't write this code that finds file mod times and here it is BTW. So if you think of any ways to make this code read protected file/folder modification time info, please let me know.

 

<!-- Taken from 'wookie at no-way dot org' on http://www.php.net/function.filemtime -->

<?php

 

  function mostRecentModifiedFileTime($dirName,$doRecursive) {

   

    $d = dir($dirName);

    $lastModified = 0;

   

    while($entry = $d->read()) {

     

      if ($entry != "." && $entry != "..") {

       

        if (!is_dir($dirName."/".$entry)) {

          $currentModified = filemtime($dirName."/".$entry);

        }

        else if ($doRecursive && is_dir($dirName."/".$entry)) {

          $currentModified = mostRecentModifiedFileTime($dirName."/".$entry,true);

        }

       

        if ($currentModified > $lastModified){

          $lastModified = $currentModified;

        }

      }

    }

   

    $d->close();

    return $lastModified;

  }

   

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.