File Operations (2), file operations
Directory operations
// Create the directory mkdir ("./aa ");
// The Directory to be deleted must be empty before you can delete rmdir ("./img ");
// Move the directory file rename ("./img", "./ajax/img ");
File Operations
// Create a file touch ("./11.txt ");
// Copy the file copy ("./11.txt","./ajax/11.txt ");
// Delete the file unlink ("./11.txt ");
// Read the file content (local, remote) echo file_get_contents ("http://www.baidu.com ");
// Write the file content (overwrite) file_put_contents ("./ajax/11.txt"," hello world ");
// Read the file and output readfile ("./11.txt ");
// Put each row of data in the file into the array $ arr = file ("./ajax/test. php ");
File Content operations
// Open the file resource $ fp = fopen ("./11.txt"," ");
// Write content fwrite ($ fp, "ceshi ");
// One read row echo fgets ($ fp );
// Read multi-row echo fread ($ fp, 2 );
// Close the file resource fclose ($ fp );
Traverse directories
/* $ Fname = "./ajax ";
$ D = opendir ($ fname );
While ($ url = readdir ($ d ))
{
Echo $ fname. "/". $ url. "<br> ";
}
Closedir ($ d );*/
// Delete a folder
// Rmdir ()
// Give me a folder and delete it.
Function Del ($ url)
{
// Clear
$ D = opendir ($ url );
While ($ u = readdir ($ d ))
{
If ($ u! = "." & $ U! = "..")
{
$ Fname = $ url. "/". $ u;
If (is_file ($ fname ))
{
Unlink ($ fname );
}
Else
{
Del ($ fname );
}
}
}
Closedir ($ d );
// Delete
Rmdir ($ url );
}
Del ("./ajax ");