PATH:
home
/
centosnipponia
/
cronjscript
/
old
<?php //echo create_insert_delivery("testpath/SND-SHIPMENT6-347897-2021092085115.csv"); //echo move_file_to_old_folder("testpath/","SND-SHIPMENT6-347897-2021092085115.csv"); //var_dump(scandir("testpath/"), array(".", "..")); check_and_update_deliveries(); function check_and_update_deliveries() { $containing_files=glob('/home/rtjjjjmy/public_html/wh/ediwarehousebot/Delivery/*.csv'); foreach($containing_files as $file) { $path_parts = pathinfo($file); //$file_name=basename($file); $path_to_file=$path_parts['dirname']."/"; $file_name=$path_parts['basename']; $file_path=$path_to_file.$file_name; $sql_command=create_insert_delivery($file_path); run_sql_command($sql_command); move_file_to_old_folder($path_to_file,$file_name); //echo $file_name; //echo "<br>"; //echo $path_to_file; } } function move_file_to_old_folder($path_to,$file_name) { $source = $path_to.$file_name; $destination = $path_to."old/".$file_name; return rename($source, $destination) ? "OK" : "ERROR" ; } function create_insert_delivery($filepath) { //echo $filepath; $sql_delivery = "INSERT INTO `moltransfers` (`Company`, `Tranfernbr`, `Make`, `Model`, `Colour`, `Speed`, `qty`, `DestinationName`, `DestinationAddress`, `DestinationZip`, `DestinationCity`, `DestinationCountry`, `Phone`, `DateCreated`, `Shipmentnbr`, `ShipmentLinenbr`, `DeliveryDate`, `VIN`, `created_at`, `Status`) VALUES "; $max_rows=count_csv_rows($filepath); $row_current_nbr=0; $lines=""; $row_comma_separated=""; $first_row=true; $file = fopen($filepath,"r"); while($row_current_nbr<$max_rows-1) { $row_current_nbr=$row_current_nbr+1; if($first_row) { $first_row=false; fgetcsv($file); } else { $row_array =explode(";",fgetcsv($file)[0]); $row_comma_separated="('".implode("','", $row_array)."','".date("Y-m-d")."','Delivered'),"; //echo ($row_comma_separated); } $lines.= $row_comma_separated; } fclose($file); $sql_delivery.=$lines; $sql_delivery=substr_replace($sql_delivery,";",-1); return $sql_delivery; } function count_csv_rows($filepath) { $file = fopen($filepath,"r"); $count_rows=0; while(! feof($file)) { $count_rows=$count_rows+1; fgetcsv($file); } fclose($file); return $count_rows; } function run_sql_command($sql) { $servername = "localhost"; $username = "rtjjjjmy_appodoouser"; $password = "$8di*Trrg4~J"; $dbname = "rtjjjjmy_appodoo"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->exec($sql); echo "New record created successfully"; } catch(PDOException $e) { echo $sql . "<br>" . $e->getMessage(); } $conn = null; } ?>
[+]
..
[-] sql_command_update_trn.php
[edit]
[-] createandsend.php pld 14102021
[edit]
[-] createandsend.php-change-contact-address
[edit]
[-] createandsend.php-old2
[edit]
[-] createandsend.php-old11
[edit]
[-] createandsend.php - old major change 11102021
[edit]
[-] config.php-staging
[edit]
[-] createandsend.php-old1
[edit]
[-] createandsend.php-old181121
[edit]
[-] sql_command_del.php-old15102021
[edit]
[-] createandsend.php-170222
[edit]
[-] createandsend.php-301121
[edit]