Jump to content

Export Results to Text Then Save File On server


anilvaghela

Recommended Posts

Hello Guys n Girls...

 

I have a script below...

 

<?php
$host = 'servername';
$user = 'username';
$pass = 'password';
$db = 'stats_db';
$table = 'ref_export';
$file = 'export';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$values1 = mysql_query("show columns from ref_col");
//$i = 0;
//$txt_output = "";
if (mysql_num_rows($values1) > 0) {
while ($row = mysql_fetch_assoc($values1)) {

$txt_output .= $row['Field'].",";
$i++;

}
$txt_output = substr( $txt_output , 0, -1 );
$txt_output .= $row[$i-1];
//$txt_output .= "\r\n";
}

//$values = mysql_query("select order_id as 'order', name_id as 'id', name_ch as name, parent_id as 'parent-id',level, aggregate, pseudo, ps_id as 'ps-id', replevel, class, audit_list.audit from ref_export inner join audit_list on (ref_export.audit=audit_list.id) order by order_id asc");
$values = mysql_query("select * from ref_export order by order_id asc");
while ($rowr = mysql_fetch_row($values)) {
$txt_output .= "\r\n";
for ($j=0;$j<$i-1;$j++) {
$txt_output .= $rowr[$j].",";
}
$txt_output .= $rowr[$i-1];
//$txt_output .= "\r\n";
}

//$filename = $file."_".date("Y-m-d_H-i",time());
$filename = "channels";
header("Content-type: application/vnd.ms-notepad");
header("Content-disposition: txt" . date("Y-m-d") . ".txt");
header( "Content-disposition: filename=".$filename.".txt");
print $txt_output;
exit;
?>

 

 

This will export the results into a text file which is right.... but I dont want it to export into a text file i want it to save the text file on the server instead....

 

how do i do this???

 

please help...

 

anil vaghela

 

 

<?php
file_put_contents('/logs/data/stats/content/tmpupload',$txt_output);
?>

But you need to ask yourself is that really the location you want those files, is it really a path that is relative to root, or is it actually relative to the script. By the way I do not assume it will work. The function works just fine and is built into php.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.