At 17:40 11.03.2003, Doug Coning said:
--------------------[snip]--------------------
>header('Content-Type: image/jpeg');
>$im = imagecreatefromjpeg("001_SM77GR.jpg");
>imagejpeg($im,'',85);
>imagedestroy($im);
>
>I copied this code from PHP.net.  However, when I run the above code, it
>doesn't download the image, it just shows the image in the browser.  I'm
>using IE 6 for my browser.
>
>How I get PHP to download this image?
--------------------[snip]-------------------- 

To have a browser handling data it receives as downloadable file you must
set a Content-Type it cannot handle inline, and specify a disposition and
filename, such as:

Content-Type: application/octet-stream
Content-Disposition: attachment;filename="myfile.jpg"
Content-Length: 1234

Note that it is always a good idea to tell the browser the size of a file
it is about to receive. Since imagejpeg() outputs the stream directly and
doesn't giv you any size information, you may use output buffering to
obtain the stream, like:

    ob_start();
    imagejpeg($im, '', 85);
    $image_size = ob_get_length();
    $imgstream = ob_get_contents();
    ob_end_clean();

    // continue as outlined above
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment;filename="myfile.jpg"');
    header('Content-Length: ' . $image_size);
    echo $imgstream;
    exit;


-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to