Copy CodeThe code is as follows:
Common file manipulation functions
The first part of the file read and write and create delete rename, etc.
Before you start working on a file, let's see if it's a file file that can be read and writable.
$file = "Test.txt";
if (file_exists ($file))//disk-broken file exists
{
echo "File exists
";
}else
{
echo "File does not exist, created";
$FP =fopen ($file, "w");//read-only mode creation
Fclose ($FP);
}
if (Is_file ($file))
{
echo "is a file
";
}
if (Is_dir ($file))
{
echo "is the directory
";
}
if (is_executable ($file))
{
echo "File executable
";
}
if (is_readable ($file))
{
echo "File readable
";
}
if (is_writable ($file))
{
echo "file can be written
";
}
chmod ($file, 0777);//Full Access
The pattern Description Number 1 means that the file is executable, the number 2 means that the file is writable, and the number 4 means that the file is readable--schema addition represents permissions
$FP =fopen ("Test.txt", "A +");//Open with append read and write mode
When you open a remote file
$FP =fopen ("Test.txt", "a+b"); remember to add B;
$content =fread ($FP, 70);//Read 70 bytes
echo "1. {$content}
";//output
Fwrite ($fp, "I am the Asdddddddddddddddddddddddddddddddddxxxxxxxxx");//Append to write
$content =file_get_contents ("test.txt");//Read file read remote file recommended with this function
$content =file_get_contents ("http://www.jianlila.com");
echo "2. {$content}
";
File_put_contents ("Test.txt", "I love my parents asdddddddddddddddddddddddddddddddddxxxxxxxxx");
Output to File
Fclose ($FP);//close file handle
$FP =fopen ("Test.txt", "A +");
$content =fread ($fp, FileSize ("test.txt"));
Read all content filesize ($file)//File bytes
echo "3. {$content}
";
$FP =fopen ("Test.txt", "R");
echo "one character". Fgetc ($FP). "
";//read one character
$FP =fopen ("Test.txt", "R");
echo "one line". Fgets ($FP). "
";//read one line of characters
$FP =fopen ("Test.txt", "R");
echo "remaining data";
Fpassthru ($FP);
echo "
";//output remaining data can be used to output the binary file
Copy ("Test.txt", "recommended courtesy of. txt");
File copy
if (File_exists ("Love my parents. txt"))
{
Unlink ("Love my parents. txt");
Delete files if they exist
}
Rename ("Recommended"), "Love my parents."
File Rename
if (File_exists ("recommended"))
{
RmDir ("recommended");//Delete folder
}else
{
mkdir ("recommended");//Create a folder
}
Get File Information function
$file = "Test.txt";
echo "File Size". FileSize ($file). " Bytes
";
echo "file type". FileType ($file). "
";
The file type here is not what we saw.. txt this type of 20-finger fifo,char,dir,block,link,file and unknown
$FP =fopen ($file, "R");//Open File
Print_r (Fstat ($FP));//Print file information
echo "Current file path information". __file__. "
";
echo "The directory where the current file is located". DirName (__file__). "
";
echo "Current file name". basename (__file__). "
";
Print_r (Stat ($file));//Print file information
?>
http://www.bkjia.com/PHPjc/322562.html www.bkjia.com true http://www.bkjia.com/PHPjc/322562.html techarticle Copy the code as follows:? PHP//Common file operation function//First part of file read and write and create delete rename, etc.//before we begin to manipulate the file, let us first determine whether it is a text ...