|
Posted by shadowman on 06/04/07 18:11
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: File Transfer');
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 png file on the server
called temp.png This file contains the correct png, so I know the
getPNG() function, and everything before that is working correctly.
However, the file that gets downloaded to the user's computer is
incorrect and will not display correctly in an image viewer.
I've tried comparing the file saved on the server with the file saved 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 the file to the user without saving it on the server, but this
also gave me the same results.
Any ideas? Why is the file not transferring correctly?
Thanks in advance.
[Back to original message]
|