fread(): read of 8192 bytes failed with errno=21 Is a directory in

Viewed 1331

I was editing WordPress and the error message below came out.

" Notice: fread(): read of 8192 bytes failed with errno=21 Is a directory in /home/c7006248/public_html/ondine199918.com/wp-includes/functions.php on line 6574"

The code is as follows.

*/
function get_file_data( $file, $default_headers, $context = '' ) {
    // We don't need to write to the file, so just open for reading.
    $fp = fopen( $file, 'r' );

    if ( $fp ) {
        // Pull only the first 8 KB of the file in.
      $file_data = fread( $fp, 8 * KB_IN_BYTES );


        // PHP will close file handle, but we are good citizens.
        fclose( $fp );
    } else {
        $file_data = '';
    }

Does anyone have any idea of a potential fix for that issue?

I would be more than grateful if you help me with a fix. Thanks in advance! :)

Hitomi


For the additional information. The error location I'm getting is " Notice: fread(): read of 8192 bytes failed with errno=21 Is a directory in /home/c7006248/public_html/ondine199918.com/wp-includes/functions.php on line 6574 "

And the line 6574 is

$file_data = fread( $fp, 8 * KB_IN_BYTES );

from the extracted code above.

Sorry for the incomplete information.

1 Answers

I guess you are trying to open a directory instead of file So you need to check if it's a file or not before trying to read the first 8kb

function get_file_data( $file, $default_headers, $context = '' ) {
    if (!is_file($path) === false) {
        return;
    }
Related