Hi,
I would like to know how to save the contents of a database to an XML or a comma-delimited file using only PHP. Below is the basic process
1. Select required data from a table in the database
2. Format the data to the required specification e.g. XML, CSV, etc
3. Create the file
4. Prompt user for a place to save the file e.g. My Documents
5. Save the file
I believe I can do the first two but I can't figure out what I need to do to create the file with PHP, prompt user, then save.
I would really appreciate your assistance.
Save contents of a database as an XML or CSV file
Moderator: General Moderators
-
canobi2004
- Forum Newbie
- Posts: 1
- Joined: Tue Jun 22, 2004 5:05 am
- protokol
- Forum Contributor
- Posts: 353
- Joined: Fri Jun 21, 2002 7:00 pm
- Location: Cleveland, OH
- Contact:
Creating the file is simple. You would basically use the [php_man]fopen[/php_man], [php_man]fwrite[/php_man], and [php_man]fclose[/php_man] functions to write the file. Then you use headers to prompt the user to save the file:
Code: Select all
<?php
$mime_type = shell_exec("file -bi "$filename"");
$file_size = filesize($filename);
header('Content-Type: '.$mime_type);
header('Content-Disposition: attachment; filename="'.$mime_type.'"');
header('Content-Length: '.$file_size);
@readfile($file);
exit;
?>hi protokol,
i tried out ur script, but it is not working for me somehow. the result is the following warning:
i tried out ur script, but it is not working for me somehow. the result is the following warning:
what do i do wrong ?Warning: Cannot modify header information - headers already sent by (output started at /srv/www/htdocs/intranet/phpFunctions/constants.inc.php:61) in /srv/www/htdocs/intranet/timetablePlanning/export.php on line 105
....