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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:51:59+00:00 2026-05-15T11:51:59+00:00

I want to upload an image from disk, resize it, and then upload it

  • 0

I want to upload an image from disk, resize it, and then upload it to Amazon S3.

However, I cant get the proper image output from imagejpeg().

heres my code:

$sourceUrl = $_FILES['path']['tmp_name'];       
$thumbWidth = '100';
$thumbid = uniqid();
$img = imagecreatefromjpeg($sourceUrl);
$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
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// output the image 
imagejpeg($tmp_img);

// upload thumbnail to s3
$s3->putObjectFile($tmp_img, "mybucket", $thumbid, S3::ACL_PUBLIC_READ);

Firebug gives me this error :

illegal character
[Break on this error] (�����JFIF���������>CREATOR: g...(using IJG JPEG v62), default quality\n

If I modify imagejpeg this way,

imagejpeg($tmp_img, 'abc.jpg');

then I get the same error. 🙁

Can i get some help here please ?

  • 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-05-15T11:51:59+00:00Added an answer on May 15, 2026 at 11:51 am

    If you check the documentation of imagejpeg you can see it outputs the image, it means the way you call it it gets sent to the browser. You can get it to save to a file the second way you call it – by passing a filename in the second parameter.

    Also, $tmp_img is an image resource, not a ready-to-use image file.

    I don’t know how your upload function works, but: if you need the file contents to upload, do it like this:

    ob_start();
    imagejpeg($tmp_image);
    $image_contents = ob_get_clean();
    $s3->putObjectFile($image_contents, "mybucket", $thumbid, S3::ACL_PUBLIC_READ);
    

    if you need a filename to upload:

    $filename = tempnam(sys_get_temp_dir(), "foo");
    imagejpeg($tmp_image, $filename);
    $s3->putObjectFile($filename, "mybucket", $thumbid, S3::ACL_PUBLIC_READ);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need big help from you,I want to upload image using amazon s3 web
I want to select an image from an android image gallery and upload it
I want to create an application where I want to upload image from the
Hope you all will be fine. Actually i want to upload image files from
i want to upload image int the bitmap object from asp.net, the image is
I want use from multiple upload image in codeigniter but problem is here that
I am new in Iphone development. I want to upload image from Iphone library
i want to upload an image from the client's system, through javascript and store
I want to upload a image(UIImage) from ios app to django website.(where has forms
How to do the following: I want to have a link [upload image] which

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.