anilvaghela Posted October 27, 2009 Share Posted October 27, 2009 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 Link to comment https://forums.phpfreaks.com/topic/179179-export-results-to-text-then-save-file-on-server/ Share on other sites More sharing options...
WolfRage Posted October 27, 2009 Share Posted October 27, 2009 Well instead of serving the file up to the user you need to use file_put_contents() to save the string to a file on the server. Link to comment https://forums.phpfreaks.com/topic/179179-export-results-to-text-then-save-file-on-server/#findComment-945341 Share on other sites More sharing options...
anilvaghela Posted October 27, 2009 Author Share Posted October 27, 2009 but how would i put the file into the following directory: /logs/data/stats/content/tmpupload i dont know where to begin with the function you assume will work.... thanks Link to comment https://forums.phpfreaks.com/topic/179179-export-results-to-text-then-save-file-on-server/#findComment-945342 Share on other sites More sharing options...
WolfRage Posted October 27, 2009 Share Posted October 27, 2009 <?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. Link to comment https://forums.phpfreaks.com/topic/179179-export-results-to-text-then-save-file-on-server/#findComment-945346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.