PATH:
home
/
centosnipponia
/
public_html
/
wh
/
eurostock
<?php function convertAnsiToUtf8($fileName) { // Read the contents of the ANSI CSV file $fileContent = file_get_contents($fileName); // Convert ANSI to UTF-8 $fileContent = iconv('Windows-1251', 'UTF-8', $fileContent); // Write the UTF-8 content back to the file, replacing the original content file_put_contents($fileName, $fileContent); // echo "Conversion for $fileName successful!"; } function check_for_updates($folder_path) { $containing_files=glob($folder_path.'*.csv'); foreach($containing_files as $file) { $path_parts = pathinfo($file); $path_to_file=$path_parts['dirname']."/"; $file_name=$path_parts['basename']; convertAnsiToUtf8($file_name); // only for capetown and eurostock csv. Do not use in other scripts $folder_path=$path_to_file.$file_name; $sql_command=create_insert_db($folder_path); if(run_sql_command($sql_command)){ move_file_to_old_folder($path_to_file,$file_name); } } } function move_file_to_old_folder($path_to,$file_name) { $source = $path_to.$file_name; $destination = $path_to."imported/".$file_name; print_r($destination); return rename($source, $destination) ? "OK" : "ERROR" ; } 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 = "centosni_nipbuser"; $password = "*aohZ@_.hHVR"; $dbname = "centosni_nipbdb"; $sql_ran_normally=False; try { $conn = new PDO("mysql:host=$servername;charset=utf8mb4; dbname=$dbname", $username, $password); // set the PDO error mode to exception poly shmantiko to charset $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->exec($sql); if($sql!="SELECT 1") { $sql_ran_normally=True; } echo "New record created successfully"; } catch(PDOException $e) { echo $sql . "<br>" . $e->getMessage(); } $conn = null; return $sql_ran_normally; } function fix_file($filepath) { $fhandle = fopen($filepath,"r"); $content = fread($fhandle,filesize($filepath)); $content = str_replace(",", "", $content); $fhandle = fopen($filepath,"w"); fwrite($fhandle,$content); fclose($fhandle); } ?>
[+]
..
[+]
error csv
[-] functions_csv_handle.php
[edit]
[+]
imported
[-] sql_command_import_eurostock.php
[edit]
[-] .htaccess.disabled
[edit]