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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:41:21+00:00 2026-06-05T22:41:21+00:00

I have encountered a problem with creating a thumbnail from an uploaded image file,

  • 0

I have encountered a problem with creating a thumbnail from an uploaded image file, then to upload it to the server.

As of now, I have a function that creates the thumbnail, saves it as a temp and returns it to the caller.

Then what I try to do, is upload that created thumb image with move_uploaded_file(tempthumb, path);

Here is the createThumb function and the caller:

function createThumb( $image, $thumbWidth )
{
  // load image and get image size
  $img = imagecreatefromjpeg( "{$image}" );
  $width = imagesx( $img );
  $height = imagesy( $img );

  // calculate thumbnail size
  $new_width = $thumbWidth;
  $new_height = floor( $height * ( $thumbWidth / $width ) );

  // create a new temporary image
  $tmp_img = imagecreatetruecolor( $new_width, $new_height );

  // copy and resize old image into new image 
  imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

  return $tmp_img;

}

return $tmp_img; // Here I return the new image. Is this the proper way to get a binary image back??

Here is the caller:

$thumb = createThumb($_FILES['propform-previmg']['tmp_name'], $max_previmg_width); 
        $filenamepath = $src_dir . '/thumb/' . $_FILES['propform-previmg']['name'];
        if ( !move_uploaded_file($thumb, $filenamepath ))
            echo "Error moving file {$filenamepath}";

I tried to just upload the uploaded file directly without trying to make a thumbnail first, and that worked fine. So I guess there is some error with the variable I return from the createThumb function, but I can’t figure out exactly what.

Also, I need to do the upload from the caller code, and not inside the createThumb function with imagejpeg(file, path).

Thank you!

  • 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-05T22:41:22+00:00Added an answer on June 5, 2026 at 10:41 pm

    First line from the manual:

    This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP’s HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.

    Your thumbnail wasn’t uploaded, it even isn’t a file yet, but just an image resource. To write the image, call something like imagejpeg($resource, $filename) to write it to the path specified in $filename.

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

Sidebar

Related Questions

I'm creating an Android game and I encountered a problem. I have 2 threads:
I have encountered a problem twice now whereby a producer thread produces N work
I have encountered a problem in my application. I have two forms, one that
I'm currently exploring powershell capabilities, but I have encountered a problem that I have
I have encountered a problem in my program that has me somewhat stumped. I
The following diagram illustrates a problem I have encountered creating a Manhattan diagram: Overlapping
I have encountered a problem when trying to select data from a table in
I have encountered a problem where in my database I have a column that
I have encountered a problem in my application and realized that I could fix
I have recently delved into creating custom ViewGroups and have encountered a problem I

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.