wp_check_filetype_and_ext [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Attempt to determine the real file type of a file.
If unable to, the file name extension will be used to determine type.
If it's determined that the extension does not match the file's real type, then the "proper_filename" value will be set with a proper filename and extension.
Currently this function only supports validating images known to getimagesize().
Source
<?php
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
$proper_filename = false;
// Do basic extension validation and MIME mapping
$wp_filetype = wp_check_filetype( $filename, $mimes );
extract( $wp_filetype );
// We can't do any further validation without a file to work with
if ( ! file_exists( $file ) )
return compact( 'ext', 'type', 'proper_filename' );
// We're able to validate images using GD
if ( $type && 0 === strpos( $type, 'image/' ) && function_exists('getimagesize') ) {
// Attempt to figure out what type of image it actually is
$imgstats = @getimagesize( $file );
// If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME
if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) {
// This is a simplified array of MIMEs that getimagesize() can detect and their extensions
// You shouldn't need to use this filter, but it's here just in case
$mime_to_ext = apply_filters( 'getimagesize_mimes_to_exts', array(
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/tiff' => 'tif',
) );
// Replace whatever is after the last period in the filename with the correct extension
if ( ! empty( $mime_to_ext[ $imgstats['mime'] ] ) ) {
$filename_parts = explode( '.', $filename );
array_pop( $filename_parts );
$filename_parts[] = $mime_to_ext[ $imgstats['mime'] ];
$new_filename = implode( '.', $filename_parts );
if ( $new_filename != $filename )
$proper_filename = $new_filename; // Mark that it changed
// Redefine the extension / MIME
$wp_filetype = wp_check_filetype( $new_filename, $mimes );
extract( $wp_filetype );
}
}
}
// Let plugins try and validate other types of files
// Should return an array in the style of array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename )
return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes );
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp check filetype and ext « WordPress Codex
Description. Attempts to determine the real file type of a file. If unable to, the file name extension will be used to determine type. If it's determined that the ...
codex.wordpress.org - wp_check_filetype_and_ext Wordpress hook details - Adam R Brown
Detailed information about every action hook and filter used in WordPress. Makes Plugin API easier to use. Lists appearance, file location, and deprecation data ...
adambrown.info - wp_check_filetype_and_ext
Function and Method Cross Reference. wp_check_filetype_and_ext(). Defined at : /wp-includes/functions.php -> line 1687. Referenced 2 times: ...
phpxref.ftwr.co.uk - wp_check_filetype_and_ext() WordPress function reference ...
Attempt to determine the real file type of a file. If unable to, the file name extension will be used to determine type.
queryposts.com