Does anyone know how to get the standard Windows "Save As..." dialogue box to pop up?
I'm using PHP to create a comma seperated file, generated from a MySQL database. I now need to prompt the user to save this file to a location on their computer.
I can force the file onto a users C: drive using the following code, but this doesn't strike me as being particularly elegant.
$file_string = date("dmy_Hi" . ".txt";
$db = mysql_connect("server", "root"
mysql_select_db("user", $db);
@$sub = fopen("c:/" . $file_string,"w"
if (!$sub) echo "error creating c:/" . $file_string;
@$result = mysql_query("SELECT * FROM table", $db);
$column_number = mysql_num_fields($result);
if (!$column_number) echo "error reading table header";
unset($header);
for($i=0 ; $i<$column_number ; $i++) $header[$i] = mysql_field_name($result, $i);
fputs($sub,"'" . implode("','",$header) . "'\r\n"
while($data = mysql_fetch_array($result))
{
unset($to_file);
for($i=0;$i<$column_number;$i++)
{
$to_file[$i] = preg_replace("/\'/","''",stripslashes(trim($data[$header[$i]])));
}
fputs($sub,"'" . implode("','",$to_file) . "'\r\n"
}
$msg = "File ". $file_string . " succesfully downloaded to your C: drive.";
fclose($sub);
Any ideas appreciated.
I'm using PHP to create a comma seperated file, generated from a MySQL database. I now need to prompt the user to save this file to a location on their computer.
I can force the file onto a users C: drive using the following code, but this doesn't strike me as being particularly elegant.
$file_string = date("dmy_Hi" . ".txt";
$db = mysql_connect("server", "root"
mysql_select_db("user", $db);
@$sub = fopen("c:/" . $file_string,"w"
if (!$sub) echo "error creating c:/" . $file_string;
@$result = mysql_query("SELECT * FROM table", $db);
$column_number = mysql_num_fields($result);
if (!$column_number) echo "error reading table header";
unset($header);
for($i=0 ; $i<$column_number ; $i++) $header[$i] = mysql_field_name($result, $i);
fputs($sub,"'" . implode("','",$header) . "'\r\n"
while($data = mysql_fetch_array($result))
{
unset($to_file);
for($i=0;$i<$column_number;$i++)
{
$to_file[$i] = preg_replace("/\'/","''",stripslashes(trim($data[$header[$i]])));
}
fputs($sub,"'" . implode("','",$to_file) . "'\r\n"
}
$msg = "File ". $file_string . " succesfully downloaded to your C: drive.";
fclose($sub);
Any ideas appreciated.