Re: downloading files created by PHP

From: Date: Wed, 14 May 2003 16:01:58 +0000
Subject: Re: downloading files created by PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147603@lists.php.net to get a copy of this message
I'm a little confused. Does it just display the information on the page? I'm not sure what that header() stuff is doing... On Wed, 14 May 2003, Eddie Shipman wrote: > Do you save it as csv? > > Here's how I let me members download a copy of their schedule: > > <?php > include("../mysql.php"); > include("../dbconnect.inc"); > $db = new dbstuff; > $team = $_GET['team']; > $db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect); > $sql = "select teamname from teams where id=".$team; > $query = $db->query($sql); > list($teamname)=$db->fetch_row($query); > $sql = "select g.gamenum, "; > $sql = $sql." DAYNAME(g.gamedate) gamedayname, "; > $sql = $sql." MONTHNAME(g.gamedate) gamemonthname, "; > $sql = $sql." DAYOFMONTH(g.gamedate) gamedaynum, "; > $sql = $sql." lower(date_format(g.gamedate, '%l:%i')) gametime, "; > $sql = $sql." h.teamname, "; > $sql = $sql." v.teamname, "; > $sql = $sql." f.field_name "; > $sql = $sql."from games g, "; > $sql = $sql." teams v, "; > $sql = $sql." teams h, "; > $sql = $sql." _fields f "; > $sql = $sql."where g.homeid = h.id and "; > $sql = $sql." g.visitorid = v.id and "; > $sql = $sql." f.id = g.fieldid and "; > $sql = $sql." (g.homeid=".$team." or g.visitorid=".$team.") > "; > $sql = $sql."order by g.gamenum"; > $query = $db->query($sql); > if (!$query) { > echo('Team:'. $team.mysql_error()); > } else { > $content = "GameNo\tGame Day\tGame Time\tVisitor\tHome\tField\n"; > // Get results > while (list($gameno, $gamedayname, $gamemonthname, $gamedaynum, $gametime, > $hometeam, $visitteam, $field_)=$db->fetch_row($query)) { > $content = $content."$gameno\t$gamedayname $gamemonthname > $gamedaynum\t$gametime\t$visitteam\t$hometeam\t$field_\n"; > } > } > > header("Content-type: application/vnd.ms-excel"); > header("Content-disposition: inline; filename=".$teamname."_schedule.xls"); > header("Content-Length: " . strlen($content)); > header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); > header("Pragma: public"); > echo("$content"); > ?> > > It's called like this from another script... > > if (($submit == "Download") and ($team < 100) and ($team > 0) ) { > header("Location: download_schedule.php?team=$team"); > > > > No, I have a site where the user can write a query (through a form) and > > then run it, and the results of the query are saved to a file. He needs > > to be able to download that file after it's created. > > > <SNIP> > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > >

« previous php.general (#147603) next »