You are here: Re: Problem with http File Transfer « PHP Programming Language « IT news, forums, messages
Re: Problem with http File Transfer

Posted by Mike P2 on 06/04/07 19:35

On Jun 4, 2: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: 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.

What is your error reporting level set to? If you set it to E_ALL at
the top of the script, does it complain about not being able to modify
header information? I'm thinking that you might have some empty lines
in myImageSave.php outside of the PHP block or before the <?php line
in this file.

-Mike PII

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация