NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
downloading .gz file and SRV


Joined: 10 Nov 2006
Posts: 3
Reply with quote
Hi guys,
while trying to perform a simple download page I cannot make SRV to work it correctly.
Here we go:

Code:

<?php
$extension = "application/x-zip-compressed";
$size=filesize("MyFile.txt.gz");
$blob = fopen("MyFile.txt.gz", "rb");
ob_start();
header("Content-type: $extension");
header("Content-Disposition: attachment; filename=\"MyFile.txt.gz\"; size=$size");
fpassthru($blob);
ob_end_flush();
?>


The stream in the debugger is written correctly (I see it in the Output pane). The browser open the download in progress windows at the ob_end_flush() command. But when the scripts exits (at the last ?>) an error popup windows overlaps saying that the server is not available and/or not found (unfortunately the messages are in italian so thath I cannot tell the exact counterpart in english Crying or Very sad ).

I tried al the possible configurations of content-type and disposition as well as putting or not filename (quoted or no) and size.
I installed the same thing on an old NT with IIS and it worked fine: why can't I use the "download as" feature in a debugging session? Of course it also doesn't work if I refer locally to the SRV server with the external browse (not debugging). It seems to me a real problem of the SRV component.


Pls note the the code snippet is for reference, and in my app I cannot use the tmp file as a link, because in the most general way the blob is coming as a stream from a DB (using PDO drivers).

Thanks a lot in advance.

Marco
View user's profileFind all posts by mlomonacoSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
First it is not ZIP Smile and therefore correct headers would be:

Content-Type: application/x-tar
Content-Encoding: gzip

in case of xxx.tar.gz

or

Content-Type: application/x-gzip
in case of pure gz file

also I'd highly recommend you not to use output buffer. It will make your server load much higher and won't help with anything.
It's purpose is to output content by bigger chanks when you echo from php by very small ones. In your case passthrough is good enough. BTW, don't forget to CLOSE file handle!!! Smile or just use readfile() instead.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 10 Nov 2006
Posts: 3
Reply with quote
Hi Dimitri, thank you for your reply.

Simply what you suggest doesn'work: as I mentioned, I tried all the possible configurations of Content-type (I paradoxally cannot download simple text/plain files, nor .doc, .pdf or .xls files): it seems to me something is going wrong on the behaviour of the server itself, since the download apparently starts but never suceeds.

I just dont know what to do (a problem of system rights ?) and the example should be pretty simple to reproduce: does it work on your PC? I am using a winXP machine.

Concerning the ob_*() functions: I well know that it is not recommended but they were put there just to distinguish the appereance of the two message windows on http client side.

Whilst, for closing the handle, well the PHP manual does not mention that is mandatory to close it (you can see the help section for fpassthru() as they don't close the handle in their snippet): but thanks for the hint anyway, I'd better to close it.

Can you pls confirm to me that you can reproduce this behaviour on XP?

Does any other guy ever had my same problem?

Thanks again

Marco
View user's profileFind all posts by mlomonacoSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Your code is broken
a) ob_ must be removed or with big files you'll easily exhause memory beyound memory limit or at least will load your life server too much.
b) you need correct Content-Type header (not Content-type, not applixation/x-zip)
c) it's recommended to use FULL file path and handle errors if file is not found or not opened. In case of error, you may want to issue Location: header to redirect browser to html with error message.

Let know if after corrections it still does not work for you.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 10 Nov 2006
Posts: 3
Reply with quote
Hi dimitri,
ok for the mystype, but even with your suggestion I cannot move on.
I have made 2 screenshots with the code just after the fpassthru() and after the exit of the script.
(I cut out the ob_*() functions that were put only for sake of clarity for interaction between the creation of the output buffer and browser message boxes display).

First screen shot



You can see the breakpoint, the file exists and the filename is a full-length path. Also notice the first window for download in progress. Note that the ouput is correctly written (well something is written and I rely on the fact that is the correct gzip).

Second screen shot



Notice that the script as exited and the second error message box appears on the browser.

All the code you see is the only code that is executed (no include/require).
The <?php and ?> were omitted in the screenshot for saving space in the window.


That's all, let me know.

Thanks in advance

Marco
View user's profileFind all posts by mlomonacoSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
I think you missed Content-Length header. It's a required header (see RFC 1945, p10.4)

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
correct headers would be:

Code:
 header("Content-Type: $extension");
 header("Content-Length: $size");
 header("Content-Disposition: attachment; filename=\"MyFile.txt.gz\"");

For further problems related to php and http, please consult with php manual and mentioned RFC.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
downloading .gz file and SRV
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic