So, whenever the user downloads a .csv file from the site, another .csv file gets created to my ../includes folder so it means there is a .csv file download located inside the downloads folder and another .csv file created where my .php files are located. Is there any way to prevent the file inside my .php files to be created and instead only the download? thanks! here's the code.
<?php
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_NAME", "envoy");
function db_connect() {
$db = mysqli_connect(DB_HOST, DB_USER, DB_PASS) or die("ERROR!");
mysqli_select_db($db, DB_NAME);
return $db;
}
$db = db_connect();
date_default_timezone_set("EST5EDT");
$date = date('m-d-Y,h.i.sa');
$date2 = date('m/d/Y');
$filename = $date.'.csv';
$fp = fopen($filename,"w");
$sql2 = "SELECT sku as Sku,name as 'Brochure Name',location as Location FROM brochureinfo where modified LIKE '$date2' ORDER BY name ";
$rs2 = mysqli_query($db, $sql2);
mysqli_close($db);
$row = mysqli_fetch_assoc($rs2);
$seperator = "";
$comma = "";
foreach ($row as $name => $value){
$seperator.= $comma. ''.str_replace('','""',$name);
$comma=",";
}
$seperator .= "
";
echo $seperator;
mysqli_data_seek($rs2,0);
while ($row = mysqli_fetch_assoc($rs2)){
$seperator = "";
$comma = "";
foreach ($row as $name => $value){
$value = str_replace( array( "" , "
", "
", "
" ) ,'' , $value);
$value = str_replace('</b><br>','',$value);
$value = str_replace('<b>','',$value);
$value = str_replace('<br>','',$value);
$value = str_replace('<br />','',$value);
$seperator.= $comma. ''.str_replace('','""',$value);
$comma=",";
}
$seperator .= "
";
//putting the heading into the csv file
fputs($fp,$seperator);
}
header('Content-Type: text/csv');
header("Content-Disposition: attachment; filename=$date.csv");
header('Pragma: no-cache');
readfile($filename);
fclose($fp);
if it cannot be prevented, maybe a way to change the location where it is created instead of my includes folder maybe another one? Thank you very much!