WordPress.org

Ready to get started?Download WordPress

Forums

image dimensions on upload hack (3 posts)

  1. anmar
    Member
    Posted 9 years ago #

    Hi there,

    Like the guy who asked about image dimensions a while ago (http://wordpress.org/support/topic/14684), I feel it's important to have the width and height specified in all image tags. I believe I figured out some simple changes, all in wp-admin/upload.php, to make the image dimensions show in the sample code, so that the uploader can then just copy and paste.

    I don't know if there's a reason for this information to have been left off before - if so, please tell me about it.

    Anyway, here's how to make it work.

    In wp-admin/upload.php, around line 202:
    replace this code:

    ----------- old code ---------------------
    if ( ereg('image/',$img1_type) )
    $piece_of_code = "<img src='" . get_settings('fileupload_url') ."/$img1_name' alt='$imgdesc' />";
    else
    $piece_of_code = "<a title='$imgdesc'>$imgdesc</a>";


    --------------- new code ---------------------
    $image_attr = getimagesize($pathtofile);
    $image_width = $image_attr[0];
    $image_height = $image_attr[1];

    if ( ereg('image/',$img1_type) )
    $piece_of_code = "<img src='" . get_settings('fileupload_url') ."/$img1_name' width='$image_width' height='$image_height' alt='$imgdesc' title='$imgdesc' />";
    else
    $piece_of_code = "$imgdesc";


    // get thumbnail information
    $path = explode('/', $pathtofile);
    $thumbpath = substr($pathtofile, 0, strrpos($pathtofile, '/')) . '/thumb-' . $path[count($path)-1];
    $image_attr = getimagesize($thumbpath);
    $image_width = $image_attr[0];
    $image_height = $image_attr[1];


    if ( ereg('image/',$img1_type) )
    $thumb_code = "<img src='" . get_settings('fileupload_url') ."/thumb-$img1_name' width='$image_width' height='$image_height' alt='$imgdesc' title='$imgdesc' />";
    else
    $thumb_code = "$imgdesc";


    // &&& end new code
    $piece_of_code = htmlspecialchars( $piece_of_code );
    $thumb_code = htmlspecialchars( $thumb_code );
    ?>


    <h3><?php _e('File uploaded!') ?></h3>
    <?php printf(__("Your file %s was uploaded successfully!"), $img1_name); ?>
    <?php _e('Here’s the code to display it:') ?>
    <?php echo $piece_of_code; ?>

    <!-- thumbnail code added by AMT &&& -->
    <?php _e('Here’s the code to display the thumbnail image') ?>
    <?php echo $thumb_code; ?>
    `
    ----------- end code ---------------

    It would be great if this could be standard in the future, but again, I don't know the reasoning behind leaving it out to begin with.

  2. Kafkaesqui

    Posted 9 years ago #

    "I don't know if there's a reason for this information to have been left off before - if so, please tell me about it."

    Perhaps the devs haven't thought of it? Anyway, I use a similar hack in my installation, without problems.

  3. mpm
    Member
    Posted 8 years ago #

    Is there anyway to limit the image dimensions thru hacking upload.php?
    ie. I don't want posters to able to upload images that are over 250 pixels high or 470 pixels wide.

Topic Closed

This topic has been closed to new replies.

About this Topic