Jump to content

Resize copied image on upload as thumbnail


Russia

Recommended Posts

I am working on an uploader and slowly getting it working, I am uploading 3 images at once, and setting arrays for each one as keys, with an increment of ++1. I am wanting to resize the image before it gets copied to the thumbnail folder.

I have this code.

<?php
if (isset($_POST['addpart'])) {

    $image = $_FILES['images']['tmp_name'];
    $name  = $_POST['username'];
    $i     = 0;
    foreach ($image as $key) {

        $fileData   = pathinfo(basename($_FILES["images"]["name"][$i]));
        $fileName[] = $name . '_' . uniqid() . '.' . $fileData['extension'];
        move_uploaded_file($key, "image/" . end($fileName));

    //get uploaded file info before we proceed with resize
    $image_name = $_FILES['images']['name'][$i]; //file name
    $image_size = $_FILES['images']['size'][$i]; //file size
    $image_temp = $_FILES['images']['tmp_name'][$i]; //file temp
    $image_size_info    = getimagesize($image_temp); //gets image size info from valid image file


        copy("image/" . end($fileName), "image_thumbnail/" . end($fileName));
        $i++;
    }
    echo 'Uploaded<br>';
    echo 'Main Image - ' . $fileName[0] . '<br>';
    echo 'Extra Image 1 - ' . $fileName[1] . '<br>';
    echo 'Extra Image 2 - ' . $fileName[2] . '<br>';
    echo '<hr>';

}
?>



Everything works with it. As you see, I started on getting the file info, but after that I am totally stuck on what to do after to resize the image proportionally with a maximum width of xPX and height to match it without looking distorted.

Any help would be really appreciated. Thank You.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.