HI All
My problem is this. I am querying a database and then writing the results to txt file. That works and is fine. But i would like to be able to allow the user to download the file to their local machine.
To forcing the download I have put this headers (many versions of "application")
header("Content-Type: application/RFC822");
or
header( "Content-type: application/x-gzip" );
or
header("Content-Type: application/txt");
or
header("Content-Type: application/octet-stream");
AND
header("Content-Disposition: attachment; filename=fede2.txt");
or
header("Content-Disposition: inline; filename=fede2.txt");
This is fine in that it brings up the download box but when i open the file locally it's E M P T Y !!! Sgrunt!!!!
I have tried with 3 SO e 4 browser!!!!
Many thanks
Fede Rico 🙁((((((((((((((((
=====================/////////////
My code is below:
<?
if (file_exists("fede2.txt"))
{
unlink("fede2.txt"); // CANCELLO IL FILE SE ESISTE
}
touch("fede2.txt"); // LO RICREO
$fp = fopen("fede2.txt", 'w');
include ('../../configu.php');
$link = mysql_pconnect($host,$user,$pass);
if (! $link)
die ( "Impossibile connettersi al db $db");
mysql_select_db($db)
or die ("Impossibile selezionare il db $db" .mysql_error ());
$os = mysql_query("Select * from merca where (validate='1') order by data,merca_id DESC");
while ($osp = mysql_fetch_array($os))
{
$content .= "<B>";
$parola =""; // LIBERO RISULTATO
if ( $osp[nero] == "0")
{
// NON E' NERETTO SOLO LE PRIME 3 PAROLE
$tag = explode(" ", $osp[annuncio]);
// RICOMPONGO
$n="0";
foreach ( $tag as $key => $val )
{
$parola .= $val." ";
if ( $n == '2' )
{
$parola .= "<B>";
}
$n++;
} // CHIUSURA FOREACH
$content .= $parola." Tel. ".$osp[telefono];
// CONTROLLO CAMPI FAX MAIL
if (!empty ($osp[fax]))
$content .= " Fax ".$osp[fax];
if (!empty ($osp[mail]))
$content .= " ".$osp[mail];
}
if ( $osp[nero] == "1")
{
// SE E' NERETTO TUTTO ANNUNCIO
$content .= $osp[annuncio]." Tel. ".$osp[telefono];
// CONTROLLO CAMPI FAX MAIL
if (!empty ($osp[fax]))
$content .= " Fax ".$osp[fax];
if (!empty ($osp[mail]))
$content .= " ".$osp[mail];
$content .= "<B>";
}
$content .= "\n";
}
fwrite($fp, $content);
header("Content-Type: application/RFC822");
header("Content-Disposition: attachment; filename=fede2.txt");
fclose ($fp);
exit;
?>