$inbound = "inbound";
$completed = "completed";
foreach (glob($inbound . "/*.csv") as $file) {
$row = 1;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row == 1) { // skipping header row
} else {
$data = array_map('mysql_real_escape_string', $data);
$insertquery = "INSERT INTO i_orders (io_company, io_name, io_email, io_addr1, io_addr2, io_city, io_country, io_orderdate, io_orderno, io_ordstatus, io_postalcode, io_shipname, io_state, io_phone, io_desc, io_qty, io_sku, io_weight, io_tcost, io_cost, io_orderid) VALUES ('$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[9]', '$data[10]', '$data[11]', '$data[12]', '$data[13]', '$data[14]', '$data[15]', '$data[16]', '$data[17]', '$data[18]', '$data[19]', '$data[20]')";
mysql_query($insertquery) or die(mysql_error());
}
$row++;
}
fclose($handle);
rename($file, $completed . "/" .date('YmdHis', strtotime("now")) . "_" . substr($file, 8));
} else {
echo "Failure: file " . $file . " can not be opened!";
}
}
exit;