Jump to content

Recommended Posts

Hi,

 

Ive got this script for upload and resize pict. But! What if I want to upload 2 images in same time?

 

This is the form:

 

<form action="index.php" method="POST" enctype="multipart/form-data">

    <input type="hidden" name="MAX_FILE_SIZE" value="200000">

    <input type="file" name="imagefile[1]"><br>

    <input type="file" name="imagefile[2]"><br>

    <input type="submit" name="upload" value="Upload Image">

</form>

 

 

and this is the script for upload 1 file:

 

 

// Get the details of "imagefile"

$filename = $_FILES['imagefile']['name'];

$temporary_name = $_FILES['imagefile']['tmp_name'];

$mimetype = $_FILES['imagefile']['type'];

$filesize = $_FILES['imagefile']['size'];

 

//Open the image using the imagecreatefrom..() command based on the MIME type.

switch($mimetype) {

    case "image/jpg":

    case "image/jpeg":

        $i = imagecreatefromjpeg($temporary_name);

        break;

    case "image/gif":

        $i = imagecreatefromgif($temporary_name);

        break;

    case "image/png":

        $i = imagecreatefrompng($temporary_name);

        break;

}

 

//Delete the uploaded file

unlink($temporary_name);

 

//Save a copy of the original

imagejpeg($i,"images/uploadedfile.jpg",80);

 

//Specify the size of the thumbnail

$dest_x = 150;

$dest_y = 150;

 

//Is the original bigger than the thumbnail dimensions?

if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {

    //Is the width of the original bigger than the height?

    if (imagesx($i) >= imagesy($i)) {

        $thumb_x = $dest_x;

        $thumb_y = imagesy($i)*($dest_x/imagesx($i));

    } else {

        $thumb_x = imagesx($i)*($dest_y/imagesy($i));

        $thumb_y = $dest_y;

    }

} else {

    //Using the original dimensions

    $thumb_x = imagesx($i);

    $thumb_y = imagesy($i);

}

 

//Generate a new image at the size of the thumbnail

$thumb = imagecreatetruecolor($thumb_x,$thumb_y);

 

//Copy the original image data to it using resampling

imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));

 

//Save the thumbnail

imagejpeg($thumb, "images/thumbnail.jpg", 80);

 

?>

Link to comment
https://forums.phpfreaks.com/topic/53564-upload-and-resize-multiple-images/
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.