mirror of
git://develop.git.wordpress.org/
synced 2025-04-08 14:13:27 +02:00
Code Modernization: Use file_get_contents()
in wp_get_image_mime()
.
`file_get_contents()` is faster than `fread()`, because the PHP core can decide how to best read the remaining file; it could decide to issue just one `read()` call or `mmap()` the file first. Per the PHP manual, `file_get_contents()` or `stream_get_contents()` is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by the OS to enhance performance. Reference: [https://www.php.net/manual/en/function.file-get-contents.php PHP Manual: file_get_contents()]. Follow-up to [50810], [52696], [52698]. Props maxkellermann. See #55069. git-svn-id: https://develop.svn.wordpress.org/trunk@52701 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4689322d44
commit
13485e11c5
@ -3265,12 +3265,8 @@ function wp_get_image_mime( $file ) {
|
||||
return $mime;
|
||||
}
|
||||
|
||||
$handle = fopen( $file, 'rb' );
|
||||
if ( false === $handle ) {
|
||||
return false;
|
||||
}
|
||||
$magic = file_get_contents( $file, false, null, 0, 12 );
|
||||
|
||||
$magic = fread( $handle, 12 );
|
||||
if ( false === $magic ) {
|
||||
return false;
|
||||
}
|
||||
@ -3289,8 +3285,6 @@ function wp_get_image_mime( $file ) {
|
||||
) {
|
||||
$mime = 'image/webp';
|
||||
}
|
||||
|
||||
fclose( $handle );
|
||||
} catch ( Exception $e ) {
|
||||
$mime = false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user