473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

imageJPEG() - saving result from browser with filename while using sessions

Hi,

I've created a PHP file called filename.jpg. It outputs a JPG. I've set up
a .htaccess file to force the filetype to PHP. The file is displayed in a
page on a browser. I cannot get the damn thing to save as my suggested
filename or even as anything but a BMP in IE6. I've tried a bunch of
different combinations of the content-type and content-disposition (inline,
attachment, filename, name) headers. Nothing has worked.

I've tried all combinations of the following header() string (regex for
brevity-I didn't actually use the regex characters):

Content-(T|t)ype: image/jpeg(; (file)?name="?xx.jpg"?)?

with and without:
Content-(D|d)isposition: (inline|attachment)(; (file)?name="?xx.jpg"?)?

followed by:
ImageJPEG($im,'',60);

After many hours pounding my head against the wall and RingTFingM, I
realized 2 things as I was writing this post.

The first is that I'm using session_start(). Take it out and I have no
trouble.

The second is that I've encountered this problem before, spent hours on it,
and finally gave up and passed all parameters to the script by $_GET.

I'd rather not do that again. The image is being used as a server-side
image map. Does anyone know how I can use session_start AND the
Content-disposition header? I've tried placing the header before
session_start, to no avail.

Thanks a bunch,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.GlassGiant.com
Jul 17 '05 #1
3 3207
Shawn Wilson wrote:
I've created a PHP file called filename.jpg. It outputs a JPG. I've set up
a .htaccess file to force the filetype to PHP. The file is displayed in a
page on a browser. I cannot get the damn thing to save as my suggested
filename or even as anything but a BMP in IE6. I've tried a bunch of
different combinations of the content-type and content-disposition (inline,
attachment, filename, name) headers. Nothing has worked. The first is that I'm using session_start(). Take it out and I have no
trouble.

The second is that I've encountered this problem before, spent hours on it,
and finally gave up and passed all parameters to the script by $_GET.


You have a browser problem :)
What you describe does not happen for Mozilla :))

Based on the fact that removing session_start() made me think that could
be something with the headers; so I tried removing headers from the
script. The end result was:

I have another php script that sets $_SESSION['txt'] without ini_set()s
and outputs a <img src="xx.jpg.php"/> (no .htaccess)

<?php // xx.jpg.php
ini_set('session.use_cookies', '0');
ini_set('session.cache_limiter', '');
ini_set('session.cache_expires', '');
session_start();

$im = imagecreate(200, 60);
$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 10, 20, $_SESSION['txt'], $black);

header('Content-Type: image/jpeg');
header('Content-Disposition: inline; filename="xx.jpg"');
imagejpeg($im, '', 60);
imagedestroy($im);
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Pedro Graca <he****@hotpop.com> wrote in message news:<c1*************@ID-203069.news.uni-berlin.de>...
Shawn Wilson wrote:
I've created a PHP file called filename.jpg. It outputs a JPG. I've set up
a .htaccess file to force the filetype to PHP. The file is displayed in a
page on a browser. I cannot get the damn thing to save as my suggested
filename or even as anything but a BMP in IE6. I've tried a bunch of
different combinations of the content-type and content-disposition (inline,
attachment, filename, name) headers. Nothing has worked.

The first is that I'm using session_start(). Take it out and I have no
trouble.

The second is that I've encountered this problem before, spent hours on it,
and finally gave up and passed all parameters to the script by $_GET.


You have a browser problem :)
What you describe does not happen for Mozilla :))

Based on the fact that removing session_start() made me think that could
be something with the headers; so I tried removing headers from the
script. The end result was:

I have another php script that sets $_SESSION['txt'] without ini_set()s
and outputs a <img src="xx.jpg.php"/> (no .htaccess)

<?php // xx.jpg.php
ini_set('session.use_cookies', '0');
ini_set('session.cache_limiter', '');
ini_set('session.cache_expires', '');
session_start();

$im = imagecreate(200, 60);
$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 10, 20, $_SESSION['txt'], $black);

header('Content-Type: image/jpeg');
header('Content-Disposition: inline; filename="xx.jpg"');
imagejpeg($im, '', 60);
imagedestroy($im);
?>


Just a follow-up. This worked great. I didn't think it would because
I expected it not to read the cookie info after session.use_cookies
was turned off. But apparently it reads the sessionid from the
cookie, uses it to load the session variables, then turns cookies off
before it sends the cookie back to the browser. All of which makes
perfect sense now that I type it out and really think it through.

All browsers I test on save as jpg now, though NS6 disregards
suggested filename. But the important thing was to allow them to save
as jpg. Filename was just a bonus.

End result is:
http://www.glassgiant.com/misc_magic_makeover.php
if you're interested.

Thanks Pedro,
Shawn
Jul 17 '05 #3
Shawn Wilson wrote:
Just a follow-up. This worked great.


You had me wondering here :)
Thanks for the feedback
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: GameDev | last post by:
I have a section of my website where customers can login and download a few select files. The download links are to php scripts that decide which files to download. Generally it works fine....
1
by: Phil Powell | last post by:
I am using the imagejpeg() and the imagegif() (also imagepng(), etc.) commands that will write an image Object back into an existing image in a directory. Everything works fine, except that when...
4
by: Jan Nordgreen | last post by:
The following code only generates the first csv file. The second request is just ignored. What am I doing wrong? I am using Mozilla Firefox, Windows XP, and Xampp. <?php require...
22
by: Theo | last post by:
Question for the group The authentication system for the site Im working on seems to function properly and all is good. A session keeps track of everything and a cookie is used to accept or deny...
3
by: Bob Bedford | last post by:
I'm trying to add an imagejpeg result as an attachment of an email. For creating the email I'm using phpmailer class (http://phpmailer.sourceforge.net/) Now I do create an image from a jpeg file...
4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
9
by: she_prog | last post by:
Dear All, I need to save the content of a panel to a bitmap. The panel can have many child controls which also need to be saved. The problem would be solved if I could have the panel saved to a...
2
by: MoroccoIT | last post by:
I am saving a value ID using sessions on this feedback Form, but at times, if the visitor takes too long to type a a feedback, the session times out and the user received an error message. Please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.