Re: Download File Problem - text not appearing on downloaded file

From: Date: Tue, 20 Nov 2001 09:28:55 +0000
Subject: Re: Download File Problem - text not appearing on downloaded file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-75220@lists.php.net to get a copy of this message
Joe, I have been there....:-) I use this scripts <? function detect_browser($variable) { if(eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})", $variable)) { $content = "ie"; } else { $content = "nn"; } return $content; } # Send the file to the downloaders browser # $file_dl = $base_dir.$file; if (detect_browser($HTTP_USER_AGENT) == "ie") { Header("Content-type: application/force-download"); } else { Header("Content-type: application/octet-stream"); } Header("Content-Length: ".filesize($file_dl)); Header("Content-Disposition: attachment; filename=$file"); Header("Cache-Control: no-cache, must-revalidate"); //HTTP/1.1 Header("Pragma: no-cache"); //HTTP/1.0 readfile($file_dl); ?> The first time I run this script, I works fine. The file downloads properly to the client machine with the right size and content. Most of the file is text file. After some times, I met the same problem as yours. The file size is 0. I don't know, perhaps I change the browser setting or my Admin change the Apache settings, PHP or some thing else. I ask everywhere, many mailing list. and I gave up. I just change it to Header("Location: $url.$filename"); It works but there is a funny things. The file can be downloaded properly if the file (with such an extension) has been opened with notepad. If not, the file will opened in the browser. :-).......it's an experience..... Gilijk ----- Original Message ----- From: "Joe Van Meer" <joe@coastaldestination.com> To: <php-general@lists.php.net> Sent: Monday, November 19, 2001 10:43 PM Subject: [PHP] Download File Problem - text not appearing on downloaded file > Hi there. I managed to get the prompt for a file download when a user clicks > on a text link. The file downloads properly to the client machine, howevr, > when I open up the file there is no content. What do I have to add to the > following code to get the content sent back to the user? > > Thx Joe :) > > <?PHP > > header("Content-type: application/octet-stream"); > header("Content-Disposition: attachment; filename=file.txt"); > > ?> > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#75220) next »