Reading and Writing Binary Data in a File
<?php
$binfile = "data.txt";
if (file_exists ($binfile)){
try {
if ($readfile = fopen ($binfile, "rb+")){
$curtext = fread ($readfile,100);
echo $curtext; //Hello World!
fwrite ($readfile, "Hi World!");
fclose ($readfile);
}
} catch (exception $e) {
echo $e->getmessage();
}
} else {
echo "Sorry, file does not exist.";
}
?>
Related examples in the same category