01-09-2008, 12:52 PM
|
#2 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
|
Well, to start off, you have to have decided upon your format. If you want it in plain XML it is quite simple. But human readable, at least quickly so, has to be done differently.
A good way to start is:
PHP Code:
// Make sure you test security, test the
// $_GET['var'] validity and sanitize all input.
// Mine: C:\Program Files\Xampp\htdocs
$szServerRoot = $_SERVER['DOCUMENT_ROOT'];
// .htaccess in this dir should deny from *
$szSecureFolder = szServerRoot . '/admin/downloads';
// A simple filename
$szFileName = 'email_dump.txt';
$szFullName = $szSecureFolder . '/' . $szFileName;
$db = mysl(...) or die(mysql_error());
mysql_select_db('MyDb');
// The following command outputs each column seperated by a tab
// and a row seperated by a linefeed; plenty readable.
$result = mysql_query('SELECT * FROM myTable INTO OUTFILE \''.$szFullName.'\';');
if($isValidRequest && $result) {
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: public');
header('Content-Description: File Transfer');
header('Content-Type: plain/text');
header('Content-Disposition: attachment; filename='.$szFileName);
header('Content-Transfer-Encoding: ascii');
header('Content-Length: ' . filesize($szFullName));
@readfile($szFullName);
} else {
die('Error encountered: '.mysql_error());
}
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
|
|
|
|