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("myImag eSave.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. 7 4132
On Jun 4, 2:11 pm, shadowman <shadow...@noem ail.comwrote:
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("myImag eSave.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
Mike P2 wrote:
>
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.
No errors coming up in my log, but I checked the myImageSave.php file,
and sure enough, there were 4 linefeeds after the ?>
Removing those fixed the problem. Thanks for your help! It makes sense,
although I never would have thought about that.
shadowman wrote:
Mike P2 wrote:
>> 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.
No errors coming up in my log, but I checked the myImageSave.php file,
and sure enough, there were 4 linefeeds after the ?>
Removing those fixed the problem. Thanks for your help! It makes sense,
although I never would have thought about that.
In addition to what Mike said - you're script is very unsafe. What
happens if you get two people who try to generate the files at almost
exactly the same time? Since you're using the same filename for all of
them, one will overwrite the other.
You should generate a unique filename for each one, then delete it at
the end (or after some period of time, anyway).
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
Jerry Stuckle wrote:
shadowman wrote:
>Mike P2 wrote:
>>> 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. No errors coming up in my log, but I checked the myImageSave.php file, and sure enough, there were 4 linefeeds after the ?>
Removing those fixed the problem. Thanks for your help! It makes sense, although I never would have thought about that.
In addition to what Mike said - you're script is very unsafe. What
happens if you get two people who try to generate the files at almost
exactly the same time? Since you're using the same filename for all of
them, one will overwrite the other.
You should generate a unique filename for each one, then delete it at
the end (or after some period of time, anyway).
Roger that. I was really only creating the file on the server for
debugging purposes.
I think what I really want to do is skip that altogether. More along the
lines of:
$im = getPNG($data);
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Type: image/png');
header('Content-Disposition: attachment; filename=
"Graph.png" ');
header("Content-Transfer-Encoding: binary");
ImagePNG($im);
Thanks for your help!
shadowman <sh*******@noem ail.comwrote:
> <?php require("myIma geSave.php"); //contains getPNG() function
$QUERY_STRIN G = $_SERVER['QUERY_STRING']; $data = explode("&", $QUERY_STRING);
$image = ('./temp.png'); $im = getPNG($data);
if(ImagePNG($i m, $image)) { header('Content-Description: File Transfer'); header('Content-Type: application/force-download'); header('Content-Type: image/png');
Did you copy this from someplace? An HTTP response only gets one
Content-Type header. The first one is going to be ignored.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Tim Roberts wrote:
shadowman <sh*******@noem ail.comwrote:
><?php require("myIma geSave.php"); //contains getPNG() function
$QUERY_STRIN G = $_SERVER['QUERY_STRING']; $data = explode("&", $QUERY_STRING);
$image = ('./temp.png'); $im = getPNG($data);
if(ImagePNG($i m, $image)) { header('Content-Description: File Transfer'); header('Content-Type: application/force-download'); header('Content-Type: image/png');
Did you copy this from someplace? An HTTP response only gets one
Content-Type header. The first one is going to be ignored.
Thanks. I had been playing around with a different combination of
headers when I wasn't sure why I couldn't get this working. Red
herring, so to speak.
On Jun 4, 11:11 pm, shadowman <shadow...@noem ail.comwrote:
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("myImag eSave.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:Fil eTransfer');
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 Thisfilecontain s 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve Mack |
last post by:
I was downloading from the MSDN subscription site and
used the File Transfer Manager, and was wondering if that
was something I could use for my site? Is there an API
that allows me to build this functionality into my
website? My problem is that I have a site that has
hundreds of files on it, and my customers would like to
select 5 or 6 of them and queue them up to download.
Is this possible?
|
by: Eric Cory |
last post by:
Hello Gurus
I can't get Dart PowerFTP to do anything. I create the
ftp oblect and set the connection values, but when I do a
get, put or even an invoke for a site command, I always
get the error message "No more results can be returned by
WSALookupServiceNext."
If anyone could give me some advice either about this
problem or where to ask this question, I would apreciate
|
by: uballing |
last post by:
I am writing a "Windows Update" type application where via Web Services the client checks with the Server if he needs to download a newer version of a set of DLLs and EXE
If there is a newer version, I need to download the file from the server to the client
I wonder what is the best way to download a EXE without executing it when it arrives on the client
I have tried to using WebRequest and WebResponse, Stream, BinaryReader and...
|
by: andrea azzini |
last post by:
I'm having a trouble with HTTP file transfer.
I use an ASP file to provide controlled access to some files and stream them
back to the client by adding the "content-disposition: attachment" header.
This usually works perfectly, but I've noticed that if I try to stream a
..RAR file, the client browser does not show any "open/save" window (it
simply ignores the file transfer), and .RAR appears to be the only file type
which causes it to...
|
by: clintonG |
last post by:
After the last six days trying to download VS2005 Professional it seems
there may be a problem with my instance of the File Transfer Manager (FTM)
or somewhere in the network in between. I can't even download the measely
1.5MB GIF animator which is in the Tools folder at subscriber downloads. The
FTM keeps recycling with retries until it finally times out regardless of
the configuration settings.
I've been talking with MSDN Customer...
| |
by: Papanii |
last post by:
Hi Guys,
I am a newbie to the whole dot net framework and need a few
pointers. I want to create an file transfer program (i.e form PC to PC) but
i don't know where to start. Can anyone point me to the right resources?
Thanx..
--Papanii
|
by: BobAchgill |
last post by:
Can you point me to a simple VB .NET example of how to
receive a file from a web server using a HTTP method
available in .NET
Bob
|
by: fiona |
last post by:
Yucca Valley, CA, - October 2007: Catalyst Development Corporation,
publisher of SocketTools, SocketWrench and LogicGem, today announced
the release of Catalyst File Transfer .NET V5.0. For developers who
are creating .NET applications, the File Transfer .NET component
offers a comprehensive interface for uploading and downloading files.
The Catalyst File Transfer .NET component is a managed code component
that is fully compatible with...
|
by: snranand |
last post by:
Can some one point me to a simple java example of how to
transfer files using HTTP
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |