Jump to content

Cron job is_file not catching valid files


opalelement

Recommended Posts

For some reason, this script:

 

$maps = array(); echo "1";
if ($handle = opendir('/home2/cisarel/public_html/maps/')) { echo "2";
    while (false !== ($file = readdir($handle))) { echo "3";
        if (is_file($file) && !in_array($file, array("error_log", "update.php"))) { echo "4";
            $maps[] = "$file"; echo "5";
        }
    }
    closedir($handle); echo "6";
}

 

(ignore teh echos for numbers, those were for seeing where it went)

 

won't catch my php files when run from a cron job, but will catch them when run in a browser. I tried !is_file as a test, and it returned ., .., _vti_cnf, and store (which is a directory) in teh browser, but all of those plus my two php scripts in a cron job.

 

Does is_file not work in a cron job?

Try this:

 

$dir = "/My/Dir/";
$maps = array();

if(is_dir($dir)) {
    if($handle = opendir($dir)) {
        while(($file = readdir($handle)) !== false) {
            if($file != ".." && $file != ".") {
                 $maps[] = $file;
            }
        }
        closedir($handle);
    }
}

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.