Blog Introductions
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services.Php read File write file and delete file Php files | Php tutorials Bestitworriors
Php read File write file and delete file Php files
Php read File write file and delete file Php files | Php tutorials Bestitworriors - Php files is important for any website . We can perform various function on file . Following function perform on file oper,read,write,and close the file.We use file for multiple task in website or web application to create file and store data and retrive data and update or overrite data on file . The fopen() function use to open the file.
Some Key Points of PHP File
- fopen() is used to open the file
- File can be open with mode
- Use r to open the file for read only
- Use w to open the file for write only
- Use a to open the file for write only
- Use x to create a new file for write only
- Use r+ to Open for read and wirte
- Use w+ to open for read and write
- Use a+ to open for read and write
- Use x+ to open for read and write
Code
<?php
// Write file
$myfilename = fopen("myfile.txt", "w") or die("Unable to open file!");
$text = "Write name for file\n";
fwrite($myfilename, $text);
$txt = "Jane Doe\n";
fwrite($myfilename, $txt);
fclose($myfilename);
//Read file
$file = fopen("myfile.txt", "r") or die("Unable to open file!");
echo fread($file,filesize("myfile.txt"));
fclose($file);
?>
0 Comments