File Operations (2), file operations

Source: Internet
Author: User

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 ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.