Memory App

clearstatcache() If you call file_exists() on a file that doesn't exist, it will return FALSE until you create the file. If you create the file, it will return TRUE even if you then delete the file. However unlink() clears the cache automatically.

    // Clears the information that PHP caches about a file

    $fw = fopen ("test.txt", "w");
    fwrite ($fw, "test");
    fclose ($fw);
    echo (int) file_exists("test.txt"); // Outputs: 1

    unlink ("c:test.txt");
    echo (int) file_exists ("test.txt"); // Outputs: 1

    echo (int) file_exists ("test.txt"); // Outputs: 0

    // Gives information about a file
    $stat = stat("example.txt");
    echo 'Access time: ' . $stat['atime'];
        // file access time, 
        // this is the same as calling fileatime()

    echo 'Modification time: ' . $stat['mtime'];
        // Print file modification time, 
        // this is the same as calling filemtime()

    echo 'Device number: ' . $stat['dev'];
        // Print the device number
fstat() Gets information about a file using an open file pointer. This function is similar to the stat() function except that it operates on an open file pointer instead of a filename.


    $fp = fopen("/etc/passwd", "r"); // open a file
    $fstat = fstat($fp); // gather statistics


Top Reference > Programming