Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

[PHP] fread problem

Options
  • 21-08-2008 5:50pm
    #1
    Registered Users Posts: 4,475 ✭✭✭


    I have a piece of code that reads in a text file into a string. It finds the file no problem, but the fread() statement fails. It just doesn't put anything into the string variable. It works fine locally, but not on my web server. My local OS is Ubuntu - is it possible that's done something with permissions, line feeds, etc that would cause such an issue?[php] $fp = fopen("a/b/c.txt", "r");
    $n = fread($fp, filesize("a/b/c.txt"));
    fclose($fp);
    [/php]


Comments

  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    Look at setting error_reporting to E_ALL | E_STRICT and then set display_errors.

    [PHP]error_reporting( E_ALL | E_STRICT );
    ini_set("display_errors", 1); // Send errors to screen/STDOUT.
    $filename = 'a/b/c.txt'; // Use variable as filename is referenced more than once.

    // For debugging purposes, confirm that the file is readable.
    if ( is_readable($filename) ) {
    echo "File is readable\n";
    }
    else {
    echo "ERROR: File is not readable.\n";
    }

    $fp = fopen($filename, "r");
    if ( $fp != FALSE ) { // Always confirm that the file was opened successfully.
    $n = fread($fp, filesize($filename));
    fclose($fp);
    }
    else {
    $a = error-get-last(); // Get info about the last error.
    echo "ERROR: Unable to open file:";
    print_r( $a ); // Print out info about last error
    }
    [/PHP]


Advertisement