function delFile($dir, $fileName)
 {
     if ($fileName == "all") {
         $dirUtil = new DirUtil();
         $fileList = $dirUtil->traverse($dir);
         foreach ($fileList as $f) {
             if (!unlink("{$dir}/{$f}")) {
                 echo "false";
                 exit;
             }
         }
         echo "true";
     } else {
         $ret = unlink("{$dir}/{$fileName}");
         if ($ret) {
             echo "true";
         } else {
             echo "false";
         }
     }
 }
Exemple #2
0
/**
 * Automatically load classes' files.
 *
 * @param className	the class name to be loaded.
 */
function phpUtilAutoload($className)
{
    static $classLoader = null;
    // Created just once
    if (!isset($classLoader)) {
        // File to store the directories list
        define('SUB_DIR_FILE', 'subdir.lst');
        $subDirs = array();
        if (file_exists(SUB_DIR_FILE)) {
            // Load the subdirectories from the file
            $content = file_get_contents(SUB_DIR_FILE);
            $subDirs = explode(PHP_EOL, $content);
        } else {
            // Save the subdirectories to the file
            $subDirs = DirUtil::allSubDirs('.');
            $content = implode(PHP_EOL, $subDirs);
            file_put_contents(SUB_DIR_FILE, $content, LOCK_EX);
        }
        // Here you can configure other file extensions. Example:
        // $classLoader = new ClassLoader( $subDirs,
        // 		array( '.php', '.class.php' ) );
        $classLoader = new ClassLoader($subDirs);
    }
    // Load the class
    $classLoader->load($className);
}