Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8460065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:30:15+00:00 2026-06-10T13:30:15+00:00

I’ve been using this script to upload pictures on my website for a year

  • 0

I’ve been using this script to upload pictures on my website for a year now and I finally realised that changes has to be done. I’ve been looking all over the internet but have not yet found any proper solution, so I’ve come to you.

  • This script is currently creating and moving a thumb image into the folder ‘/images’ with the propereties 111×111.
  • I want it to also upload the original picture, how do I do that?

    if(isset($_POST['submit'])) {
    if (($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/pjpeg" || $_FILES["image"]["type"] == "image/gif" || $_FILES["image"]["type"] == "image/x-png") && ($_FILES["image"]["size"] < 4000000))
    $current_img=$_FILES['image']['name'];
    $extension = substr(strrchr($current_img, '.'), 1);
    date_default_timezone_set("Europe/Stockholm");
    $time = date("fYhis");
    $new_image = uniqid() . $time;
    $destination   = "images/".$new_image . "-thumb" . "." . $extension;
    $action = move_uploaded_file($_FILES['image']['tmp_name'], $destination);
    
    $max_upload_width = 111;
    $max_upload_height = 111;
    if($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/pjpeg"){
        $image_source = imagecreatefromjpeg($destination) ;
    } 
    if($_FILES["image"]["type"] == "image/gif"){    
        $image_source = imagecreatefromgif($_FILES["image"]["tmp_name"]);
    }
    if($_FILES["image"]["type"] == "image/bmp"){    
        $image_source = imagecreatefromwbmp($_FILES["image"]["tmp_name"]);
    }
    if($_FILES["image"]["type"] == "image/x-png"){
        $image_source = imagecreatefrompng($_FILES["image"]["tmp_name"]);
    }
    
    imagejpeg($image_source,$destination,100);
    chmod($destination,0644);
    
    list($image_width, $image_height) = getimagesize($destination);
    
    if($image_width>$max_upload_width || $image_height >$max_upload_height){
        $proportions = 1;
    
        if($image_width>$image_height){
            $new_width  = $max_upload_width;
            $new_height = round($max_upload_width/$proportions);
        }       
        else{
            $new_height = $max_upload_height;
            $new_width  = round($max_upload_height*$proportions);
        }       
    
    
        $new_image = imagecreatetruecolor($new_width , $new_height);
        $image_source = imagecreatefromjpeg($destination);
    
        imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
        imagejpeg($new_image, $destination, 100); // save
        imagedestroy($new_image);
    }
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:30:16+00:00Added an answer on June 10, 2026 at 1:30 pm

    Just upload the file into a different directory by using following code

    $originalImage  = "images/".$new_image . "-ImageName" . "." . $extension;
    
    $action = move_uploaded_file($_FILES['image']['tmp_name'], $originalImage)
    

    ;

    And use $originalImage instead of $_FILES[‘image’][‘tmp_name’] in creating thumbnail.

    Check by applying the following code

    if(isset($_POST['submit'])) {
    if (($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/pjpeg" || $_FILES["image"]["type"] == "image/gif" || $_FILES["image"]["type"] == "image/x-png") && ($_FILES["image"]["size"] < 4000000))
    $current_img=$_FILES['image']['name'];
    $extension = substr(strrchr($current_img, '.'), 1);
    date_default_timezone_set("Europe/Stockholm");
    $time = date("fYhis");
    $new_image = uniqid() . $time;
    
    $originalImage  = "images/".$new_image . "-ImageName" . "." . $extension;
    $destination   = "images/".$new_image . "-thumb" . "." . $extension;
    
    $action = move_uploaded_file($_FILES['image']['tmp_name'], $originalImage);
    
    $max_upload_width = 111;
    $max_upload_height = 111;
    if($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/pjpeg"){
        $image_source = imagecreatefromjpeg($originalImage) ;
    } 
    if($_FILES["image"]["type"] == "image/gif"){    
        $image_source = imagecreatefromgif($originalImage);
    }
    if($_FILES["image"]["type"] == "image/bmp"){    
        $image_source = imagecreatefromwbmp($originalImage);
    }
    if($_FILES["image"]["type"] == "image/x-png"){
        $image_source = imagecreatefrompng($originalImage);
    }
    
    imagejpeg($image_source,$destination,100);
    chmod($destination,0644);
    
    list($image_width, $image_height) = getimagesize($destination);
    
    if($image_width>$max_upload_width || $image_height >$max_upload_height){
        $proportions = 1;
    
        if($image_width>$image_height){
            $new_width  = $max_upload_width;
            $new_height = round($max_upload_width/$proportions);
        }       
        else{
            $new_height = $max_upload_height;
            $new_width  = round($max_upload_height*$proportions);
        }       
    
    
        $new_image = imagecreatetruecolor($new_width , $new_height);
        $image_source = imagecreatefromjpeg($destination);
    
        imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
        imagejpeg($new_image, $destination, 100); // save
        imagedestroy($new_image);
    }
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I know there's a lot of other questions out there that deal with this
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.