How to save downloaded csv file to specified directory using php -
i using php script download data database , export csv format.i can generate file problem facing gets downloaded downloads folder of computer.
i want download file specific folder.how it?
here code
$result=sqlsrv_query($conn,$stmt); $out=''; $filedate=date("y-m-d"); $output='$filedate.nrml_cash_position_trade.csv'; while ($l = sqlsrv_fetch_array($result, sqlsrv_fetch_assoc)) { foreach($l $key => $value){ //if character " exists, escape it, otherwise csv file invalid. $pos = strpos($value, '"'); if ($pos !== false) { $value = str_replace('"', '\"', $value); } $out .= '"'.$value.'",'; } $out .= "\n"; } header("content-disposition: attachment; filename= $output"); echo $out;`
Comments
Post a Comment