I’m trying to read file which is available on desktop and here is my code :
<?php
$filename = "C:\Users\User\Desktop\Goals.txt";
$file = fopen($filename, "r");
if ($file == false) {
echo("We were not able to open the selected file");
exit();
}
$filesize = filesize($filename);
$filetext = fread($file, filesize);
fclose($file);
echo("<font face = 'Yu Gothic' size ='12px'>File size : <b> $filesize bytes </b>");
echo("<pre>$filetext</pre>");
?>
I’m getting this notice and warning, when I execute the script :
Notice: Use of undefined constant filesize - assumed ‘filesize’ in C:\xampp\htdocs\Php\web_concepts\files-i-o\reading-a-file.php on line 11
Warning: fread() expects parameter 2 to be long, string given in C:\xampp\htdocs\Php\web_concepts\files-i-o\reading-a-file.php on line 11
Only thing which is executing properly is filesize i.e.
File size : 230 bytes