Code Modernization: Check if the file to retrieve metadata from in get_file_data() was successfully opened.

This avoids a fatal error on PHP 8 caused by passing a `false` value to `fread()`, instead of a file resource.

See #50913.

git-svn-id: https://develop.svn.wordpress.org/trunk@49073 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-09-30 12:18:36 +00:00
parent 63e0d969b6
commit 498fae638d

View File

@ -6040,11 +6040,15 @@ 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 = '';
}
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );