wp_check_filetype example

        if ( $fname && preg_match( '/-(?:\d+x\d+|scaled|rotated)$/', $fname ) ) {
            $number = 1;

            // At this point the file name may not be unique. This is tested below and the $number is incremented.             $filename = str_replace( "{$fname}{$ext}", "{$fname}-{$number}{$ext}", $filename );
        }

        /* * Get the mime type. Uploaded files were already checked with wp_check_filetype_and_ext() * in _wp_handle_upload(). Using wp_check_filetype() would be sufficient here. */
        $file_type = wp_check_filetype( $filename );
        $mime_type = $file_type['type'];

        $is_image    = ( ! empty( $mime_type ) && str_starts_with( $mime_type, 'image/' ) );
        $upload_dir  = wp_get_upload_dir();
        $lc_filename = null;

        $lc_ext = strtolower( $ext );
        $_dir   = trailingslashit( $dir );

        /* * If the extension is uppercase add an alternate file name with lowercase extension. * Both need to be tested for uniqueness as the extension will be changed to lowercase * for better compatibility with different filesystems. Fixes an inconsistency in WP < 2.9 * where uppercase extensions were allowed but image sub-sizes were created with * lowercase extensions. */

    $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars$filename_raw );

    $filename = str_replace( $special_chars, '', $filename );
    $filename = str_replace( array( '%20', '+' ), '-', $filename );
    $filename = preg_replace( '/\.{2,}/', '.', $filename );
    $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
    $filename = trim( $filename, '.-_' );

    if ( ! str_contains( $filename, '.' ) ) {
        $mime_types = wp_get_mime_types();
        $filetype   = wp_check_filetype( 'test.' . $filename$mime_types );
        if ( $filetype['ext'] === $filename ) {
            $filename = 'unnamed-file.' . $filetype['ext'];
        }
    }

    // Split the filename into a base and extension[s].     $parts = explode( '.', $filename );

    // Return if only one extension.     if ( count( $parts ) <= 2 ) {
        /** This filter is documented in wp-includes/formatting.php */
        
$file_path = $attachment['file']; // Could be absolute path to file in plugin.             } elseif ( is_child_theme() && file_exists( get_stylesheet_directory() . '/' . $attachment['file'] ) ) {
                $file_path = get_stylesheet_directory() . '/' . $attachment['file'];
            } elseif ( file_exists( get_template_directory() . '/' . $attachment['file'] ) ) {
                $file_path = get_template_directory() . '/' . $attachment['file'];
            } else {
                continue;
            }
            $file_name = wp_basename( $attachment['file'] );

            // Skip file types that are not recognized.             $checked_filetype = wp_check_filetype( $file_name );
            if ( empty( $checked_filetype['type'] ) ) {
                continue;
            }

            // Ensure post_name is set since not automatically derived from post_title for new auto-draft posts.             if ( empty( $attachment['post_name'] ) ) {
                if ( ! empty( $attachment['post_title'] ) ) {
                    $attachment['post_name'] = sanitize_title( $attachment['post_title'] );
                } else {
                    $attachment['post_name'] = sanitize_title( preg_replace( '/\.\w+$/', '', $file_name ) );
                }
            }
'type'         => $atts['type'],
        // Don't pass strings to JSON, will be truthy in JS.         'tracklist'    => wp_validate_boolean( $atts['tracklist'] ),
        'tracknumbers' => wp_validate_boolean( $atts['tracknumbers'] ),
        'images'       => wp_validate_boolean( $atts['images'] ),
        'artists'      => wp_validate_boolean( $atts['artists'] ),
    );

    $tracks = array();
    foreach ( $attachments as $attachment ) {
        $url   = wp_get_attachment_url( $attachment->ID );
        $ftype = wp_check_filetype( $urlwp_get_mime_types() );
        $track = array(
            'src'         => $url,
            'type'        => $ftype['type'],
            'title'       => $attachment->post_title,
            'caption'     => $attachment->post_excerpt,
            'description' => $attachment->post_content,
        );

        $track['meta'] = array();
        $meta          = wp_get_attachment_metadata( $attachment->ID );
        if ( ! empty( $meta ) ) {

            
/** * Retrieves header video settings. * * @since 4.7.0 * * @return array */
function get_header_video_settings() {
    $header     = get_custom_header();
    $video_url  = get_header_video_url();
    $video_type = wp_check_filetype( $video_urlwp_get_mime_types() );

    $settings = array(
        'mimeType'  => '',
        'posterUrl' => get_header_image(),
        'videoUrl'  => $video_url,
        'width'     => absint( $header->width ),
        'height'    => absint( $header->height ),
        'minWidth'  => 900,
        'minHeight' => 500,
        'l10n'      => array(
            'pause'      => __( 'Pause' ),
            
if ( '1' == $current_blog->archived || '1' == $current_blog->spam || '1' == $current_blog->deleted ) {
    status_header( 404 );
    die( '404 &#8212; File not found.' );
}

$file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET['file'] );
if ( ! is_file( $file ) ) {
    status_header( 404 );
    die( '404 &#8212; File not found.' );
}

$mime = wp_check_filetype( $file );
if ( false === $mime['type'] && function_exists( 'mime_content_type' ) ) {
    $mime['type'] = mime_content_type( $file );
}

if ( $mime['type'] ) {
    $mimetype = $mime['type'];
} else {
    $mimetype = 'image/' . substr( $filestrrpos( $file, '.' ) + 1 );
}

header( 'Content-Type: ' . $mimetype ); // Always send this.
$file = get_attached_file( $post->ID );

    if ( ! $file ) {
        return false;
    }

    if ( str_starts_with( $post->post_mime_type, $type . '/' ) ) {
        return true;
    }

    $check = wp_check_filetype( $file );

    if ( empty( $check['ext'] ) ) {
        return false;
    }

    $ext = $check['ext'];

    if ( 'import' !== $post->post_mime_type ) {
        return $type === $ext;
    }

    
Home | Imprint | This part of the site doesn't use cookies.