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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

[PHP] fread problem

  • 21-08-2008 4:50pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 6,571 ✭✭✭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