-1

I am using this code copied from w3cschools. It works on loaclhost xampp but not working on live server. I am getting blank page on live server. PHP code is

<?php
    $myfile = fopen("products.txt", "r") or die("Unable to open file!");
    echo fread($myfile,filesize("products.txt"));
    fclose($myfile);
?>
BSMP
  • 4,596
  • 8
  • 33
  • 44
Mehtab
  • 453
  • 5
  • 17
  • 2
    Blank page usually means syntax errors. Use error reporting http://php.net/manual/en/function.error-reporting.php – Funk Forty Niner Aug 09 '15 at 15:34
  • Does `products.txt` exist in the same folder as this script file? Does the file have the correct permissions to be read by the httpd account that apache is running under? I am assuming the LIVE server is unix – RiggsFolly Aug 09 '15 at 15:34
  • Check the error logs and ensure errors are being logged and/or displayed http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Jamie Bicknell Aug 09 '15 at 15:35
  • Use file_exists http://php.net/manual/en/function.file-exists.php in a conditional statement and make sure it can be read. Check your paths also. Too many things can go wrong here. – Funk Forty Niner Aug 09 '15 at 15:36
  • Is the `products.txt` empty? – Jo Smo Aug 09 '15 at 15:42
  • Please use absolute paths to filenames. imo Stuff like `products.txt` lives in a `data` directory. This will have a 'defined constant' such as `APP_DATA_DIR` that any part of the code can use and will always return the correct directory. Obviously, it is set differently when 'testing' but still the code doesn't change. Or you access it via a `class`, repository, proxy etc. – Ryan Vincent Aug 09 '15 at 17:49
  • Yes file exist and working fine on local host xamp but when I shifted it to live server it is showing blank page without any error... – Mehtab Aug 09 '15 at 18:51

1 Answers1

0

My problem solved by adding the code on the top of page ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); Anyone can explain it? That why it got worked.

Mehtab
  • 453
  • 5
  • 17