Argument Description
r Opens a file for reading
r+ Opens a file for both reading and writing
w Opens a file for writing only
w+ Opens a file for reading and writing
a Opens a file for appending (write-only)
a+ Opens a file for appending (read/write)
X Creates a file and opens it for writing only
x+ Creates a file and opens it for reading and writing
$file = "data.txt";
if (file_exists ($file)){
try {
if ($readfile = fopen ($file, "r")){
$curvalue = fread ($readfile,100);
echo $curvalue;
} else {
throw new exception ("the file could not be opened.");
}
} catch (exception $e) {
echo $e->getmessage();
}
} else {
echo "File does not exist.";
}
?>