|
Posted by aksharmavoice on 06/08/07 07:21
On Jun 4, 11:11 pm, shadowman <shadow...@noemail.com> wrote:
> Hello all:
>
> I have a web app that creates an image of a graph (as a png), based on
> user input of a combination of drop-down box items.
>
> I'm trying to add a function that allows the user to save the graph
> image to his hard drive, just like right-clicking on the image and
> selecting 'save image as...' There's a link next to the graph that
> should open the save image dialog. The link calls the following php script:
>
> <?php
> require("myImageSave.php"); //contains getPNG() function
>
> $QUERY_STRING = $_SERVER['QUERY_STRING'];
> $data = explode("&", $QUERY_STRING);
>
> $image = ('./temp.png');
> $im = getPNG($data);
>
> if(ImagePNG($im, $image)) {
> header('Content-Description:FileTransfer');
> header('Content-Type: application/force-download');
> header('Content-Type: image/png');
> header('Content-Length: ' . filesize($image));
> header('Content-Disposition: attachment;
> filename="Graph.png"');
> header("Content-Transfer-Encoding: binary");
> readfile($image);
>
> }
>
> exit();
> ?>
>
> So Here's the problem. This bit of code saves a pngfileon the server
> called temp.png Thisfilecontains the correct png, so I know the
> getPNG() function, and everything before that is working correctly.
> However, thefilethat gets downloaded to the user's computer is
> incorrect and will not display correctly in an image viewer.
>
> I've tried comparing thefilesaved on the server with thefilesaved to
> the user's computer, and the two files are *almost* exact, with one
> exception: The user's downloaded version has 4 extra linefeed ('0A')
> characters at the top.
>
> I realize that there's some superfluous code there -- I've tried quite a
> few variations of headers, all with the same results. I know I could
> just send thefileto the user without saving it on the server, but this
> also gave me the same results.
>
> Any ideas? Why is thefilenot transferring correctly?
>
> Thanks in advance.
remove this content from your file
header('Content-Type: image/png');
regards
amit
[Back to original message]
|