HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
File handling is an important part of any web application. You often need to open and process a file for different tasks
PHP has several functions for creating, reading, uploading, and editing files.
Be careful when manipulating files!
When you are manipulating files you must be very careful.You can do a lot of damage if you do something wrong. Common errors are: editing the wrong file, filling a hard-drive with garbage data, and deleting the content of a file by accident.
The readfile()
function reads a file and writes it to the output buffer.
Assume we have a text file called "webdictionary.txt", stored on the server, that looks like this:
The PHP code to read the file and write it to the output buffer is as follows
(the readfile()
function returns the number of bytes read on success):
<?php
echo readfile("webdictionary.txt");
?>
The readfile()
function is useful if all you want to do is open up a file and read its contents.
The next chapters will teach you more about file handling.
Assume we have a file named "webdict.txt", write the correct syntax to open and read the file content.
echo ;