wp_filesize example

// Update the attached file meta.     update_attached_file( $attachment_id$new_file );

    // Width and height of the new image.     $image_meta['width']  = $saved_data['width'];
    $image_meta['height'] = $saved_data['height'];

    // Make the file path relative to the upload dir.     $image_meta['file'] = _wp_relative_upload_path( $new_file );

    // Add image file size.     $image_meta['filesize'] = wp_filesize( $new_file );

    // Store the original image file name in image_meta.     $image_meta['original_image'] = wp_basename( $original_file );

    return $image_meta;
}

/** * Creates image sub-sizes, adds the new data to the image meta `sizes` array, and updates the image metadata. * * Intended for use after an image is uploaded. Saves/updates the image metadata after each * sub-size is created. If there was an error, it is added to the returned image metadata array. * * @since 5.3.0 * * @param string $file Full path to the image file. * @param int $attachment_id Attachment ID to process. * @return array The image attachment meta data. */
if ( $post_parent ) {
            $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
            $response['uploadedToLink']  = get_edit_post_link( $attachment->post_parent, 'raw' );
        }
    }

    $attached_file = get_attached_file( $attachment->ID );

    if ( isset( $meta['filesize'] ) ) {
        $bytes = $meta['filesize'];
    } elseif ( file_exists( $attached_file ) ) {
        $bytes = wp_filesize( $attached_file );
    } else {
        $bytes = '';
    }

    if ( $bytes ) {
        $response['filesizeInBytes']       = $bytes;
        $response['filesizeHumanReadable'] = size_format( $bytes );
    }

    $context             = get_post_meta( $attachment->ID, '_wp_attachment_context', true );
    $response['context'] = ( $context ) ? $context : '';

    
$styles = array();

    // Build an array of styles that have a path defined.     foreach ( $wp_styles->queue as $handle ) {
        if ( ! isset( $wp_styles->registered[ $handle ] ) ) {
            continue;
        }
        $src  = $wp_styles->registered[ $handle ]->src;
        $path = $wp_styles->get_data( $handle, 'path' );
        if ( $path && $src ) {
            $size = wp_filesize( $path );
            if ( ! $size ) {
                continue;
            }
            $styles[] = array(
                'handle' => $handle,
                'src'    => $src,
                'path'   => $path,
                'size'   => $size,
            );
        }
    }

    
?> </strong> </div> <?php
    $file_size = false;

    if ( isset( $meta['filesize'] ) ) {
        $file_size = $meta['filesize'];
    } elseif ( file_exists( $file ) ) {
        $file_size = wp_filesize( $file );
    }

    if ( ! empty( $file_size ) ) {
        ?> <div class="misc-pub-section misc-pub-filesize"> <?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> </div> <?php     }

    if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) {
        
/** * Filters the name of the saved image file. * * @since 2.6.0 * * @param string $filename Name of the file. */
            'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
            'width'     => $this->size['width'],
            'height'    => $this->size['height'],
            'mime-type' => $mime_type,
            'filesize'  => wp_filesize( $filename ),
        );
    }

    /** * Returns stream of current image. * * @since 3.5.0 * * @param string $mime_type The mime type of the image. * @return bool True on success, false on failure. */
    
        $stat  = stat( dirname( $filename ) );
        $perms = $stat['mode'] & 0000666; // Same permissions as parent folder, strip off the executable bits.         chmod( $filename$perms );

        return array(
            'path'      => $filename,
            /** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
            'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
            'width'     => $this->size['width'],
            'height'    => $this->size['height'],
            'mime-type' => $mime_type,
            'filesize'  => wp_filesize( $filename ),
        );
    }

    /** * Writes an image to a file or stream. * * @since 5.6.0 * * @param Imagick $image * @param string $filename The destination filename or stream URL. * @return true|WP_Error */
Home | Imprint | This part of the site doesn't use cookies.