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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:24:15+00:00 2026-06-03T03:24:15+00:00

I am writing a PHP script to dynamically resize an image. The image ID

  • 0

I am writing a PHP script to dynamically resize an image. The image ID (from a MySQL db) is passed in like this : “http://localhost/getimage/1.htm”.

When I go directly to the scrippt with a URL like above, the image is spat out perfectly. But for some reason (only in Chrome), when I link that URL to an tag it starts acting weird. When the page first loads the image loads fine, but then the loading bar spins for about 5 seconds and suddenly the image disappears and Chrome shows a “Failed to load resource” error.

Does anyone have any idea what might be causing this and, if so, how to stop it? I thought that it might have had something to do with AdBlocker, but I have disabled that and it is stil happening.

Cheers.

Edit: This is the code that I am using:

    header('Content-Type:'.$file['type']);
    header('Content-Length: ' . $file['bytes']);

    // Get size of original image
    list($o_width, $o_height) = getimagesize($file['src']);

    // Default width and height
    if (is_null($width)) {
        $width = $o_width;
    }

    if (is_null($height)) {
        $height = $width;
    }

    // Create image frame
    $image_p = imagecreatetruecolor($width, $height);

    // Generate image depending on source type
    switch ($file['type']) {
        case "image/jpeg":
        default:
            $image = imagecreatefromjpeg($file['src']);
            break;
        case "image/gif":
            $image = imagecreatefromgif($file['src']);
            break;
        case "image/png":
            $image = imagecreatefrompng($file['src']);
            break;
    }

    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $o_width, $o_height);

    // Output
    imagejpeg($image_p, null, 100);
    exit;

As you can see I am setting the content types. If it was the htm extension, confusing it, would that explain why the image loads correctly, and then unloads itself?

  • 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-03T03:24:18+00:00Added an answer on June 3, 2026 at 3:24 am

    this is not Chrome only, but IMHO it is wrong that you have this at the beginning: header(‘Content-Length: ‘ . $file[‘bytes’]); because you don’t know the actual file size, since you create the image on the fly with imagejpeg($image_p, null, 100); Try commenting out the header(‘Content-Length… line, it might fix it.

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

Sidebar

Related Questions

Im writing a php script to compare the similarity of 2 strings. This works
I'm writing a php script to crop an image. The script overwrites the 'old'
I'm writing a php script to export MySQL database rows into a .txt file
I am writing temporary PHP script to update MySQL database of my vBulletin forum.
I'm writing a PHP script and would like to present a warning message if
I suspect this is a very trivial question. I'm writing a PHP script to
I'm writing a php script that will fetch data from a given URL and
I am writing a PHP script where the inputs are: From date To date
I'm writing a PHP script that will handle requests from outside sources. Does it
I'm writing a PHP script to grab text box data from a submitted form.

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.