我有一个zip文件,其中包含一些csv文件,例如:
main_table.csv
sub_table.csv
foo_table.csv
我需要遍历内存中的每个文件并执行查询:
$path = 'C:/xampp/htdocs/xampp/content/';
$zipfile = $path.'zipname.zip';
if ($zip->open($zipfile) == TRUE) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
$table = substr($filename, 0, -4);//remove extension
$query = <<<eof
LOAD DATA INFILE '$path$filename' INTO TABLE {$table}
FIELDS OPTIONALLY ENCLOSED BY '^'
TERMINATED BY '|'
ESCAPED BY ''
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
eof;
$result = $conn->query($query) or die(mysqli_error($conn));
}
}
它成功打开了zip,但出现了
错误'$path$filename'
File 'C:\xampp\htdocs\xampp\content\main_table.csv' not found (Errcode: 2 "No such file or directory")
如何将文件名从zip传递到LOAD DATA INFILE?