Hello guys,
I am trying to create a web based application using php and mysql that allows users to download data from mysql table. In the download.php script I am using headers and I simply echo() out the data. The client's computer creates the file but the only thing that a user can read is "Resource id #2", which i really dont understand.
Here is the download.php script:
<?php
if(isset($_GET['caseNumber']))
{
// if caseNumber is set then get the file with the id from database
// This is an example of config.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '**';
$dbname = '**';
// This is an example opendb.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die ('Error connecting to mysql');
mysql_select_db($dbname);
$caseNumber = $_GET['caseNumber'];
$query = "SELECT case_description, filing_date, charges FROM INDICTMENT, CASE WHERE CASE.caseNo = INDICTMENT.caseNo AND caseNumber = '$caseNumber'";
$result = mysql_query($query)
or die("Error, query failed");
while(list($case_description, $filing_date, $charges) = mysql_fetch_array($result))
header("Pragma: public");
header ("Cache-Control: cache, must-revalidate, post-check=0, pre-check=0");
header("Content-length: . strlen($result)");
header("Content-type: text/plain");
header('Content-Disposition: attachment; filename="Case details.txt"');
echo$result;
}
?>
any idea?