Is this an error? Can someone else test?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Is this an error? Can someone else test?

Post by Stoneguard »

Ok, I have some code to pull a file and download it to the end-user's computer. The basic code is:

Code: Select all

<?php
$download_size = filesize($storedfile);
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=" . $filename . ";" );
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
?>
This code works perfectly. HOWEVER, if I make one small change by adding sessions:

Code: Select all

<?php
session_start();
// typically do session variable work here, but don't need to to get the error.
$download_size = filesize($storedfile);
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=" . $filename . ";" );
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
?>
Now my filename for the download is corrupted to the URL string that was passed to my php page and I cannot download it.

Can someone else recreate this error? If so, I will report it on the php QA boards.

I am running under Windows XP Professional on IIS and useing the ISAPI interface as opposed to the CGI interface to PHP.
chris22
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2003 9:45 pm

Post by chris22 »

Let me guess. Using Internet Explorer to download? There's hundreds of problems with IE regarding the headers. For instance, IE users can't download zip files (maybe its all files? I forget) from an https site (using sessions), no matter what headers are set.

Try another browser and see if you get the same results. As far as I know, Opera is the only one that listens to the "filename" header (IE and NS both change it to something else).
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

I would think it a little bit of a stretch to say this is a browser problem specifically.

If the code works fine in IE without a session_start (by the way ending the session end doesnt resolve the issue), then something is happening with the session_start to cause corrupted data imo. Especially since the session_start should only be occuring on the server and should not be impacting the browser at all, I do not see how you can accuse the browser of being at fault.

I will post this to the php QA site in any case, as it has had very little feedback here.

Btw, say what you like about IE, it is the industry standard for browsers and I can't imagine asking my customers to use something else.
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

if you want to see the headers being sent use mozilla firebird and install the extension that let's you view the headers... that way u can see what session_start() is doing to your code
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

ie may currently be standard, but end of life was announced. m$ wont have a new one till 2005, by then expect mozilla or opera to take over if netscape doesnt get back to its prevoius dominance.

on top of that, chances are bush will be out of office, so m$ will be told that it's practices of restoring ie to default automatically in the os start up and things like that is illegal. it'll have ot seperate the browser from the os OR include many browsers giving people a choice, either way, due to bugs in ie that others don't have, people will start migrating (if they still have brains then)
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

It looks like the problem was my own in this situation. I am not sure how, but I accidentally had some HTML code following the 'read' function and this seems to have caused the issue. It now appears to be working fine.

m3, I am by no means a Microsoft lover, but you have to face the facts of where the Industry lies at the moment. Maybe Mozilla will eventually come out with something as good, who knows? And, if you stop worrying so much about how much money Bill Gates is making, you will see some really good code has come out of the different offices within Microsoft. IE is one of the nicer pieces of work from them. And let's face it, all software has bugs. More are known in IE because more people use it, more hackers hack it, more 3rd parties customize it. If it comes to that, you could say that bugs are the whole reason everyone has moved AWAY from Netscape.

But, I am not really here to discuss browsers, jsut to use PHP, which is a very nice scripting language :) .
Post Reply