query($sql); $myfile = fopen("$file", "w+") or die("Unable to open file!"); $header = false; if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { if(!$header) { $header = array_keys($row); fputcsv($myfile, $header); $header = true; } fputcsv($myfile, $row); } } fclose($myfile); mysqli_close($cons); } function clear_db($table) { $cons = db_con(); mysqli_query($cons, "TRUNCATE " . $table); mysqli_close($cons); } function get_ftp_file($target, $remote_prefix) { $ftp_client_conn = ftp_con(); //dd($ftp_client_conn); $buff = array_reverse( ftp_rawlist($ftp_client_conn, '/' ) ); // dd($buff); $info = $f_catalog = array(); foreach ($buff as $v) { $vinfo = preg_split("/[\s]+/", $v, 9); if ( strpos($vinfo[8], $remote_prefix ) !== false ) { $f_catalog[] = $vinfo; } } dd($f_catalog); $client_catalog_server_file = "/GunPro/Data_Feeds/".$f_catalog[0][8]; ftp_pasv($ftp_client_conn, true); // download server file if ( ftp_get( $ftp_client_conn, $target, $client_catalog_server_file, FTP_BINARY ) ){ echo 'File Download successfull'; } ftp_close($ftp_client_conn); } function generate_final_inv($file, $catalogue_table, $inv_table) { $cons = db_con(); $sql = "SELECT `UPC`, `QTY AVAIL`, `product_price`, `marp` FROM $catalogue_table INNER JOIN $inv_table ON $catalogue_table.`universal_product_code` = $inv_table.`UPC` WHERE 1"; $result = $cons->query($sql); $myfile = fopen("$file", "w+") or die("Unable to open file!"); $header = false; if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { if(!$header) { $header = array_keys($row); fputcsv($myfile, $header); $header = true; } fputcsv($myfile, $row); } } fclose($myfile); } function dd($data) { echo "
"; print_r($data); echo ""; exit; } ?>