Copy codeThe Code is as follows:
<? Php
// Common file operation functions
// The first part reads, writes, creates, deletes, renames, and so on.
// Determine whether a file is readable and writable before file operations.
$ File = "test.txt ";
If (file_exists ($ file) // whether the disk disconnection file exists
{
Echo "the file exists <br> ";
} Else
{
Echo "the file does not exist. You have created it ";
$ Fp = fopen ($ file, "w"); // create in read-only mode
Fclose ($ fp );
}
If (is_file ($ file ))
{
Echo "is a file <br> ";
}
If (is_dir ($ file ))
{
Echo "is a directory <br> ";
}
If (is_executable ($ file ))
{
Echo "Executable File <br> ";
}
If (is_readable ($ file ))
{
Echo "readable file <br> ";
}
If (is_writable ($ file ))
{
Echo "file writeable <br> ";
}
Chmod ($ file, 0777); // full permission
// Mode Description: Number 1 indicates that the file is executable, number 2 indicates that the file is writable, and number 4 indicates that the file is readable. Mode addition indicates the permission.
$ Fp = fopen ("test.txt", "a +"); // use the append read/write method to open
// When opening a Remote File
// $ Fp = fopen ("test.txt", "a + B"); Remember to add B;
$ Content = fread ($ fp, 70); // read 70 bytes
Echo "1. {$ content} <br>"; // output
Fwrite ($ fp, "I am a <a href = 'HTTP: // www.jianlila.com '> </a> asdddddddddddddddddddddddddddddddddddddxxxxxxx"); // added write
$ Content = file_get_contents ("test.txt"); // This function is recommended for reading remote files.
// $ Content = file_get_contents ("http://www.jianlila.com ");
Echo "2. {$ content} <br> ";
File_put_contents ("test.txt", "I am <a href = 'HTTP: // www.aiwobama.com '> love my parents </a> asdddddddddddddddddddddddddddddxxxxxxxxx ");
// Output to file
Fclose ($ fp); // close the file handle
$ Fp = fopen ("test.txt", "a + ");
$ Content = fread ($ fp, filesize ("test.txt "));
// Read all content filesize ($ file) // number of file bytes
Echo "3. {$ content} <br> ";
$ Fp = fopen ("test.txt", "r ");
Echo "one character". fgetc ($ fp). "<br>"; // read one character
$ Fp = fopen ("test.txt", "r ");
Echo "A line". fgets ($ fp). "<br>"; // read a line of Characters
$ Fp = fopen ("test.txt", "r ");
Echo "remaining data ";
Fpassthru ($ fp );
Echo "<br>"; // the output data can be used to output binary files.
Copy ("test.txt", ".txt ");
// Copy a file
If (file_exists (" .txt "))
{
Unlink (" .txt ");
// Delete an object if any
}
Rename (" .txt", ". txt ");
// Rename the file
If (file_exists (" "))
{
Rmdir (""); // delete a folder
} Else
{
Mkdir (""); // create a folder
}
// Function for getting File Information
$ File = "test.txt ";
Echo "file size". filesize ($ file). "bytes <br> ";
Echo "file type". filetype ($ file). "<br> ";
// The file here is not the 20-point fifo, char, dir, block, link, file, or unknown type.
$ Fp = fopen ($ file, "r"); // open the file
Print_r (fstat ($ fp); // print the File Information
Echo "current FILE path information". _ FILE _. "<br> ";
Echo "directory of the current FILE". dirname (_ FILE _). "<br> ";
Echo "current FILE name". basename (_ FILE _). "<br> ";
Print_r (stat ($ file); // print the file Information
?>