CSV file, and so on.
*/
$fp =fopen (' Test.txt ', ' R '); Open File
$flag =ftruncate ($FP, 5); Intercepting files
if ($flag)//Whether the decision file is intercepted successfully
{
echo "File interception successful! ";
}
Else
{
echo "File interception failed! ";
}
Fclose ($FP); Close File
/*
*/
$fp =fopen (' Test.txt ', ' R '); Open a file as read-only
$data =fgets ($fp, 4096); Read File contents
Fseek ($fp, 100); Move the file pointer to the 100th offset shift
Fclose ($FP); Close File
/*
*/
$FP =fopen ("Test.txt", "R"); Open File
$contents =fscanf ($fp, "%st%st%sn"); Format output File contents
Print_r ($contents); Output content
Fclose ($FP); Close File
/*
*/
foreach (Glob ("*.txt") as $filename)
{
echo "FileName:". $filename;
echo "<br>";
echo "File Size:". FileSize ($filename). " n ";
echo "<p>";
}
Match all text files
function Lockfile ($FP)//Custom lock file functions
{
Flock ($FP, lock_ex) or die ("Cannot flock file"); Locked exclusively, only the current process has access to the file
}
function Unlockfile ($FP)//Custom unlock functions
{
Flock ($FP, Lock_un) or Die ("Cannot unlock file"); Release lock
}
$FP =fopen ("Test.txt", "w+"); Open File
Lockfile ($FP); Lock file
Fwrite ($fp, "hello,php tutorial"); Write to a file
Unlockfile ($FP); Unlock
Fclose ($FP); Close File
//
$file = "Test.txt"; Definition file
$FP =fopen ($file, "w"); To open a file as a write
$date = "Hello world!"; Define String
Fputs ($fp, $date); Writes a string to the specified file
Fclose ($FP); Close File
//
$list =array (
' A,b,c,d ',
' 1,2,3 '
); Defines an array as an argument to an incoming function
$fp =fopen (' Test.csv ', ' W '); Open a CSV file as a write
foreach ($list as $line)//traversing an array, writing a CSV file as a "," number as a delimiter
{
Fputcsv ($fp, Split (', ', $line));
}
$date =fread ($fp, 4096); Read File contents
Echo $date; Output file contents
Fclose ($FP); Close File
//
$fp =fopen ("Test.txt", "R"); //Open File
Echo fpassthru ($fp //reads the file data to the buffer
Fclose ($fp); //closes the file