I am trying to open a file but for some reason I cannot even though the file is there and even has 777 permission. The code is the following:
$fileatt = "/opt/lampp/htdocs/a.pdf";
echo "File size is ".filesize($fileatt)."<br>";
if (file_exists($fileatt)) {
echo "The file ".$fileatt." exist <br>";
$file = fopen($fileatt, ‘rb’);
if ($file == false) {
echo "Could not open the file !";
}
} else {
echo "The file ".$fileatt." does NOT exist <br>";
}
The result is:
File size is 1252121
The file /opt/lampp/htdocs/a.pdf exist
Could not open the file !
Why can’t I open the file ? Where is my mistake ?
Thanks
You don’t have error reporting properly set. there are 2 things to remember.
error reporting level. set by
error_reportingini directive orerror_reporting()function. should ALWAYS be at E_ALL or higher.error messages destination.
Thus, for a quick solution, put these 2 lines at the top of your script
but later set up these settings as a permanent ones for the whole site (according to the server state)
once you done it, you will have an answer to your question.
Note that you will have not a mere guess from the fellow stackoverflowers, but exact explanation of the matter from the system itself.