Re: help downloading .exe files through php/mysql

From: Date: Fri, 29 Sep 2000 21:25:11 +0000
Subject: Re: help downloading .exe files through php/mysql
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-18123@lists.php.net to get a copy of this message
On Fri, 29 Sep 2000, Tyler Longren wrote: > Hi everybody, > > How do I make this pop up a download window. I'm wanting to download > the binary file in the db. Here's my code, the name of this is get.php: > > <? > > if($id) { > @MYSQL_CONNECT("localhost","root","myfunkypass"); > @mysql_select_db("files"); > $sql = @MYSQL_QUERY("select bin_data,filetype from binary_data where > id = '$id'"); > $data = @MYSQL_RESULT($sql,0,"bin_data"); > $type = @MYSQL_RESULT($sql,0,"filetype"); > > Header("Content-type: $type"); > echo $data; > > }; > ?> > > It will display images, .jpeg, .jpg, .gif. Any image. But when it > tries to download a .exe file, it pop's up a download window, but it > makes you download get.php. After you download get.php, it has a bunch > of binary code in it, but it's not the binary of the file. > > Can anybody help me out here? Thanks! > > Regards, > Tyler Longren > Whoa, that code looks incredibly familiar :) You just need to use this line after the "header("Content-type...")" one : header("Content-Disposition: attachment; filename=$name"); Where $name should actually be the filename of the binary data you are outputting. If you are not saving the filename on your DB, oh well, you need to. I recently did an article for O'Reilly Network' PHP Devcenter on this same issue, saving and downloading binary data with MySQL. Take a look : http://www.oreillynet.com/pub/a/php/2000/09/15/php_mysql.html Best Regards, Joao -- Joao Prado Maia Web Developer Kefta, Inc. T: (415) 391-6881 ext 8008 F: (415) 391-7079

« previous php.general (#18123) next »