For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2004 > php / download









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author php / download
Sylvain LECORNE

2004-05-12, 7:21 pm

Hye,

To force to download files with the default file name I want I use that
code I found in Internet :
-------------------------------------------------------------------------
$filename = "FILES/$myfilename";
$size = filesize("$filename");

header("Content-Type: application/force-download;
name=\"$myfilename\";");
header("Content-Transfer-Encoding: binary;");
header("Content-Length: $size;");
header("Content-Disposition: attachment; filename=\"$myfilename\";");
header("Expires: 0;");
header("Cache-Control: no-cache, must-revalidate;");
header("Pragma: no-cache;");
readfile("$filename");
-------------------------------------------------------------------------
The problem is that the file downloaded is bigger that the good one, and
contains a part of the HTML page. For exemple if I have a file that just
contains "AB" when I download and open it I have :
-------------------------------------------------------------------------
AB
<HTML>
<HEAD>
<LINK rel="Stylesheet" href="INCLUDE/Style.css" type="text/css">
<TITLE> Gestión de carpetas</TITLE>
</HEAD>
<BODY>
<FORM ACTION="index.php" METHOD="post" ENCTYPE="multipart/form-data">
<TABLE BORDER=0 WIDTH="100%">
<TR BGCOLOR=#ccccff>
<TD ALIGN="left">Hola sylvain !!!</TD>
<TD ALIGN="right" WIDTH=0><A HREF=index.php?Logout=1>Logout</A></TD>
</TR>
<TR BGCOLOR=#ffffdd>
<TD COLSPAN=2 ALIGN="left">
<SELECT NAME="Li
-------------------------------------------------------------------------
In that case the variable $size is 2. I have tried various exemples from
Internet but the result is always that one...

Thanks for your help.

Sylvain.



Alvaro G Vicario

2004-05-12, 7:21 pm

*** Sylvain LECORNE wrote/escribió (Mon, 10 May 2004 16:33:57 +0200):
> The problem is that the file downloaded is bigger that the good one, and
> contains a part of the HTML page.


There obviously doesn't have to be any HTML out there. All you send to
client is received by the browser. Remove all HTML.

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Sylvain LECORNE

2004-05-12, 7:21 pm

Well,

I put a die(); after my code and it works well. With other browsers the
first code worked but IE and Lynx for example don´t treat the Content-Length
line...

Thanks for your help.

Sylvain.

"Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> escribió en
el mensaje news:1r7tutb39cutd$.1fnk1c7im2csa.dlg@40tude.net...
> *** Sylvain LECORNE wrote/escribió (Mon, 10 May 2004 16:33:57 +0200):
>
> There obviously doesn't have to be any HTML out there. All you send to
> client is received by the browser. Remove all HTML.
>
> --
> --
> -- Álvaro G. Vicario - Burgos, Spain
> --



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com