PHP-fopen() and fclose()
Fopen(): This function creates the file if the file doesn’t exists . The fopen function needs two important pieces of information to operate correctly. 1. we must supply it with the name of the file...
View ArticlePHP – Different Ways to Open a File
For many different technical reasons, PHP requires you to specify your intentions when you open a file. Below are the three basic ways to open a file and the corresponding character that PHP uses. •...
View ArticlePHP – File Write: fwrite Function
We can use php to write to a text file. The fwrite function allows data to be written to any type of file. Fwrite’s first parameter is the file handle and its second parameter is the string of data...
View ArticlePHP – File Write: Appending Data
Using the filename.txt file we created in the File Write lesson , we are going to append on some more data. PHP Code: $myFile = “filename.txt”; $fh = fopen($myFile, ‘a’) or die(“can’t open file”);...
View ArticlePHP – File Read: fread Function
The fread function is the staple for getting data out of a file. The function requires a file handle, which we have, and an integer to tell the function how much data, in bytes, it is supposed to read....
View ArticlePHP – File Read: gets Function
The fgets() filesystem function in PHP will return a line from your target file handler. This function can take up to two parameters. The first parameter is your file handler. The second parameter is...
View ArticlePHP – File Read: getc Function
The fgetc() file system function in PHP will return a single character read from a file that is opened using fopen() or fsockopen(). code <?php $file = fopen("myfile.txt", "r"); $character =...
View ArticlePHP-file functions
rename() Renames a given file rename("oldname.txt","newname.txt"); unlink() Deletes a file unlink("file.txt"); filesize() Returns the file size of a file print file("file.txt"); copy() Copys a file...
View Article