One of my php script called setoptions.php is hosted on my new vps server. However, it is not working so I setup php error log as described here and, and I see the following warning repeated in my log file:
PHP Warning: fread(): Length parameter must be greater than 0 in /var/www/html/scripts/setoptions.php on line 311
The line no # 311 is as follows in my php script:
$fname = 'myappconfig.php';
$content = fread($fhandle,filesize($fname));
How do I fix this problem under Unix/Apache/php5 server?
To fix this problem, try the following solutions:
[1] Make sure file $fname exists i.e. myappconfig.php is in path.
[2] Make sure file myappconfig.php has correct permission. Apache or any other webserver needs read-only permission for reading file.
[3] Make sure file myappconfig.php exists and size is not zero i.e. make sure file is not empty.
[4] Use is_readable() to find out whether a file exists and is readable:
$fname = 'myappconfig.php'; if (is_readable($fname)) { $content = fread($fhandle,filesize($fname)); } else { echo 'The file is not readable.'; }
[5] Also use file_exists() to check whether a file or directory exists:
$fname = 'myappconfig.php'; if (file_exists($fname)) { // do_something like as follows? // $content = fread($fhandle,filesize($fname)); } else { echo "The file $fname does not exist."; }
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop








![Explain: php_self or $_SERVER['PHP_SELF'] Usage](http://s13.cyberciti.org/images/shared/rp/3/15.jpg)


{ 1 comment… read it below or add one }
Or, you could simply: