i have a cache folder called "static"
i cant figure out how to create a code to clear the contents of the folder

i have this right now

<?php
//stop cuirous people
if ($_SERVER['REQUEST_URI']) 
	die('You cannot access this file directly.');

function remove_directory($dir) {
  if ($handle = opendir("$dir")) {
   while (false !== ($item = readdir($handle))) {
     if ($item != "." && $item != "..") {
       if (is_dir("$dir/$item")) {
         remove_directory("$dir/$item");
       } else {
         unlink("$dir/$item");
       }
     }
   }
   closedir($handle);
   rmdir($dir);
  }
}

//remove static directory
remove_directory("/static");

//make static directory
mkdir("/static", 777);

print 'Job succesfully completed.'."\n";
print 'Static directory delted'."\n";
print 'Static directory created.'."\n";
?>

but i get this error

Warning: opendir(): open_basedir restriction in effect. File(/static) is not within the allowed path(s): (/home/dbhsusb/:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/dbhsusb/public_html/clear_static.php on line 7

Warning: opendir(/static): failed to open dir: Operation not permitted in /home/dbhsusb/public_html/clear_static.php on line 7

Warning: mkdir(): open_basedir restriction in effect. File(/static) is not within the allowed path(s): (/home/dbhsusb/:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/dbhsusb/public_html/clear_static.php on line 26

i was plannin on runnin this as a cron job

    first you have to CHMOD to 777, allow write
    then, I think you have to unlink all files in a folder first
    before deleting directory with rmdir()

    rmdir ( string dirname [, resource context] )

    Attempts to remove the directory named by dirname. The directory must be empty, and the relevant permissions must permit this. Returns TRUE on success or FALSE on failure.

    more info of course at http://php.net/rmdir and http://php.net/unlink

    .

      the static folder is under public_html

        /static is not under public_html. It's directly off the root directory. That's what putting the / at the start means: "This is an absolute path". If you want a relative path, leave it off.

          To avoid problems, you might want to compute the absolute location of your /static directory - try using $_SERVER['DOCUMENT_ROOT'] to do this, then use that.

          Using relative paths for filenames for IO is a bit iffy, as I'm never 100% sure how PHP handles it, for example, in a multithreaded web server where multiple PHP threads might share a current working directory.

          Mark

            Okay,
            this is what im trying to put into my joomla site
            http://forum.joomla.org/index.php/topic,12042.msg79623.html#msg79623

            what this does is create another cache inside a folder called "static"

            what i need is a php script to empty the "static" folder from time to time (cron job)
            i can't seem to use rmdir or anything around that because when the cache files in the static folder is created, the owner of the files is "99"....which isnt me

              Write a Reply...