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 8266867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:18:58+00:00 2026-06-08T05:18:58+00:00

Here is my working image upload and rename code, I however need some assistance

  • 0

Here is my working image upload and rename code, I however need some assistance to resize the image that is being uploaded.

Upload Code:

// Upload File to Directory
    $code = md5(time());
    $image = $_FILES['userfile']['name'];
    $imagename = $code.$image;
    $file_name = basename($_FILES['userfile']['name']);
    $uploaddir = '../_gallery/' . $imagename;
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
    move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);

Store to MySQL:

$sql="UPDATE b_thome SET 
hdescription = '$front_description', 
himg = '$uploadfile', 
hndescription = '$right_description', 
hfacebook='$facebook_link', 
htwitter='$twitter_link' 
WHERE locationid = '$location'";

Is there a easy way to resize the image set 600 x 800px?

Thanks!

  • 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-08T05:19:00+00:00Added an answer on June 8, 2026 at 5:19 am

    use the GD library to resize it, it offers all the function you could ask for images management. With it you could use a function like this to create a image that is a reduction of the first one:

    function resizeImage($file, $filename, $newwidth = 800, $newheight = 600)
    {       
        $type = substr($file,strrpos($file,".")+1);
    
        switch($type) 
        {
            case 'jpg':
                $src = imagecreatefromjpeg($file);
                break;
            case 'jpeg':
                $src = imagecreatefromjpeg($file);
                break;
            case 'gif':
                $src = imagecreatefromgif($file);
                break;
            case 'png':
                $src = imagecreatefrompng($file);
                break;
            default:
                $src = imagecreatefromjpeg($file);
                break;
        }
    
        list($width,$height)=getimagesize($file);
        $tmp=imagecreatetruecolor($newwidth,$newheight);
        imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
    
        switch($type) {
            case 'jpg':
                imagejpeg($tmp,$filename,100);
                break;
            case 'jpeg':
                imagejpeg($tmp,$filename,100);
                break;
            case 'gif':
                imagegif($tmp,$filename,100);
                break;
            case 'png':
                imagepng($tmp,$filename,9);
                break;
            case 'wbm':
                imagewbmp($tmp,$filename,100);
                break;
            default:
                imagejpeg($tmp,$filename,100);
                break;
        }
        imagedestroy($src);
        imagedestroy($tmp);
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the code I'm currently working with: http://jsfiddle.net/gEMCm/ I'm trying to make an image
I am right now working with this image upload from HERE . Instead of
I have this line of CSS code here... background-image:url(upload/<?php echo $array['image']; ?>); but the
here is the working fiddle: http://jsfiddle.net/2bNsC/67/ I need to place the 3 items (text
I thought I'd put the working solution here for others interested in a code
I'm working on a project that involves uploading an image to tumblr from Python.
I've been working on getting an image to upload from my iOS app to
I have a working Ajax form, now I'm trying to add file upload to
Here is the working code in Python (using cURL): #!/usr/bin/python import pycurl c =
I'm using a script which replaces the usual file upload input with whatever image

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.