Hello,
Before you want to write text to a file, you must create a file first.
CreateFile();
To edit the file like adding/deleting lines to/from the file
EditFile();
And to read the file.
Readfile();
See some examples below.
<?php
Create/Edit/Read/ Textfiles
#===================================================
#Create textfiles (Include FileExist options) (only .txt extension)
#===================================================
$FileName = "Filename";
$NameofDirectory = "C:\Users\User\Desktop";
$FileExistOption = 0;
What todo if file exist:
0 = no action
1 = overwrite file
2 = overwrite file + create backup file.
CreateFile($FileName,$NameofDirectory,$FileExistOption);
#===================================================
#Read file (Possible to read various Filetypes: .log/.txt/.ini/.cfg.lpr)
#===================================================
$LinesofFile = Readfile($Filename,$Folder);
What info you get from file.
-FileSize in bytes
-CreationDate/Time
-ModificationDate/Time
-Number Of lines
-LineNumber
-Text from each line
!!!!EXAMPLE CODE!!!!
$Filename = "TestFile";
$Folder = "C:\Users\Danny\Desktop";
$Extension = ".txt";
$LinesofFile = Readfile($Filename,$Folder,$Extension);
$NrOfLines = ToNum($LinesofFile["NumberOfLines"]);
$FileCreationDate = $LinesofFile["TimeOfCreation"];
$FileModificationTime = $LinesofFile["TimeOfModification"];
$FileSize = $LinesofFile["FileSize"];
privmsg("Reading file: " . $Filename . "" .$Extension);
privmsg("NumberOfLines: " . $NrOfLines . "");
privmsg("Size of file: " . $FileSize . " bytes");
privmsg("Creation time: " . $FileCreationDate . "");
privmsg("Modify time: " . $FileModificationTime . "");
FOR ( $i = 0; $i <= $NrOfLines-1 ; $i = $i + 1)
$linenr = $LinesofFile[$i,"LineNumber"];
$line = $LinesofFile[$i,"Line"];
privmsg("[".$linenr."]: ".$line);
ENDFOR
!!!!!!!!!! USE THE FOR/WHILE LOOP, ONLY FOR THE LINES YOU WANT TO BE DISPLAYED ON YOUR SCREEN !!!!!!!!!!!!!!!!!!!
#===================================================
#Edit file (Possible to edit various Filetypes: .log/.txt/.ini/.cfg/.lpr)
#===================================================
$Filename = "TestFile";
$Folder = "C:\Users\Blah\Desktop";
$NewText = "TESTTEST";
$LineToEdit = -1; # -1 to create a extra line
$Extension = ".txt";
EditFile($Filename,$Folder,$NewText,$LineToEdit,$Extension);
#Delete a single line in the file.
#Set '-1' as $NewText and set $LineToEdit which line you want to delete.
$Filename = "TestFile";
$Folder = "C:\Users\Blah\Desktop";
$NewText = -1;
$LineToEdit = 5;
$Extension = ".txt";
EditFile($Filename,$Folder,$NewText,$LineToEdit,$Extension);
?>