I'm attempting to upload a zip file of CSVs (exported from my DB) into mysql tables using LOAD DATA INFILE
Mysql seems to be getting the wrong path:
For example, the following:
C:\xampp\htdocs\site/uploads/temp/1620203716052941000/ck_address_change.csv
returns this error: C:\xampp\mysql\data\xampphtdocssite\uploads\temp\1620203716052941000\ck_address_change.csv not found (Errcode: 2 "No such file or directory")
//Get file and create directory
$file = $_FILES['import_zip']['tmp_name'];
$rand = preg_replace('/(0)\.(\d+) (\d+)/', '$3$1$2', microtime()); //random folder name as will be deleted later
mkdir(dirname(__DIR__).'/uploads/temp/'.$rand, 0777);
$path = dirname(__DIR__).'/uploads/temp/'.$rand;
//Open Zip
$zip = new ZipArchive;
$res = $zip->open($file);
if($res === TRUE) {
$zip->extractTo($path);
$zip->close();
}
//Loop files
$files = array_diff(scandir($path), array('.', '..'));
foreach($files as $file){
$table_name = rtrim($file,'.csv');
$upload = $path.'/'.$file;
$q = "LOAD DATA INFILE '".$upload."' INTO TABLE $table_name";
$results = mysqli_query($db,$q) or die(mysqli_error($db));
if(!$results) {
printf("Error message: %s\n", mysqli_error($db));
}
}
//Remove Directory
array_map('unlink', glob("$path/*.*"));
rmdir($path);
How do I set the path properly for this? Or is this an issue on my local server?
Note this is just for testing use on my local server so no security issues etc.