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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:43:57+00:00 2026-05-18T21:43:57+00:00

its me again with a php problem :) Following is part of my PHP

  • 0

its me again with a php problem 🙂

Following is part of my PHP script which is rendering JPEG images.

...
$tf=$requested_file;
$image_type="jpeg";
header("Content-type: image/${image_type}");
$CMD="\$image=imagecreatefrom${image_type}('$tf'); image${image_type}(\$image);";
eval($CMD);
exit;
...

There is no syntactical error, because above code is working fine for small images, but for large images, it gives:

Error 321 (net::ERR_INVALID_CHUNKED_ENCODING): Unknown error. in the browser.

To be sure, I created two images using imagemagick from same source image – one resized to 10% of original and other 90%.

http://mostpopularsports.net/images/misc/ttt10.jpg works

http://mostpopularsports.net/images/misc/ttt90.jpg gives Error 301 in the browser.

There is a related question with solution posted by OP here Error writing content through Apache but I cannot understand how to make the fix. Can someome help me with it?

I have looked at the headers in Chrome. For the first request, everything is fine. For the second request – the request headers are all garbled.


Both images are jpeg (as they are created from imagemagick. But still to be sure I checked):

misc/ttt10.jpg: JPEG image data, JFIF standard 1.01
misc/ttt90.jpg: JPEG image data, JFIF standard 1.01

Finally, the way I fixed is, remove the Transfer-Encoding: chunked header from the response. [This header was sent by apache only when the data was large enough]. (I had an internal proxy, so did it in the proxy script – otherwise one may need to do it in apache settings).

There were some good answers and I have selected the one that helped me solve the problem best.

thanks

JP

  • 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-18T21:43:58+00:00Added an answer on May 18, 2026 at 9:43 pm

    You should debug the exact server response using netcat. But a quick look with wget --save-headers reveals that the output actually looks ok:

    HTTP/1.1 200 OK
    Date: Wed, 29 Dec 2010 12:16:03 GMT
    Server: Apache/2.2.14 (Ubuntu)
    X-Powered-By: PHP/5.2.6-3ubuntu4.6
    Set-Cookie: PHPSESSID=sjh4k63i9npk6b15uperclau75; path=/
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cache
    Keep-Alive: timeout=15, max=100
    Connection: Keep-Alive, Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: image/jpeg
    

    Your linked bug-report had an invalid “chunked,chunked” – which isn’t the case for your script. Still the chunked encoding is the problem here, as your Chrome error message shows.

    I think the problem might be PHPs output buffers. The transfer-encoding lacks the final 0\r\n to terminate the HTTP stream.

    You can try flush(), disabling PHPs output buffer, and also Apaches mod_deflate (which is an extra buffer). I’m clueless as to why PHP keeps the connection open, but it might very well be the specifc combination of eval and exit. Try rewriting your code:

    header("Content-type: image/${image_type}");
    flush();
    $func = "imagecreatefrom${image_type}";
    $image = $func($tf);
    $func = "image${image_type}";
    $func($image);
    flush();
    exit;
    

    Or if it doesn’t work. Try outputting garbage echo "0"; after the image.

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

Sidebar

Related Questions

When developing whether its Web or Desktop at which point should a developer switch
I have the following form in cakephp: <div class=quickcontactDisplay> <?php echo $form->create('Enquiry',array('action'=>'add','class'=>'quickcontact')); echo $form->hidden('visitor_id',
Sigh, regex trouble again. I have following in $text : [img]http://www.site.com/logo.jpg[/img] and [url]http://www.site.com[/url] I
I have the following jQuery code which runs when I'm clicking an option in
I am creating an interpreter for my extension to HQ9+, which has the following
I need to solve the following question which i can't get to work by
I'm trying to get into java again (it's been a few years). I never
Its possible I am just really really thick. However, looking over the SDK for
its out of question that a dao will not hold any state. however, for
Its a simple config app with 4 checkboxes and 5 textboxes, and all values

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.