Way1: управляйте потоком флагом, как показано ниже. Если какой-либо файл успешно импортирован, то измените флаг и затем установите условие для флага для отображения предупреждения.
$flag = 0;
foreach ($files1 as &$value) {
$checkfile = strpos($value,$input1 );
if($checkfile === false) {
//echo "<script>alert('Import Fail ');</script>";
}
else
{
$flag = 1;
echo "Import $value successfully! <br>" ;
// $query1 =
// "Delete FROM hklcanet_pha.psr this
// WHERE year(psr.ReportDate) = $input3
// AND month(psr.ReportDate) = $input2";
$query = "load data local infile '//192.168.100.3/Groups/$location1/Timesheet/$value'
replace
into table hklcanet_pha.psr fields terminated by ','
optionally enclosed by '"'
lines terminated by '
'
ignore 1 lines
(`ReportDate`, @dummy, @dummy, `Team_refno`,`Name/Description`,`Status`,`PIC`,`RequestDate`,`TargetEndDate`,`ActualEndDate`,`PlanStartDate`,`ActualStartDate`,`PlanUATDate`,`ActualUATDate`,`PlanImplement`,`ActualImplement` )";
//echo "Import $value successfully! <br>" ;
$result = $connection->query($query) or exit("Error code ({$connection->errno}): {$connection->error}");
}
}
if($flag == 1){
echo "<script>alert('Import Fail ');</script>";
}
unset($value);
?>
Способ 2. Получить имя успешно импортированных имен файлов и создать условия для него.
$flag = [];
foreach ($files1 as &$value) {
$checkfile = strpos($value,$input1 );
if($checkfile === false) {
//echo "<script>alert('Import Fail ');</script>";
}
else
{
//Store successful file names in array
$flag[] = $value;
echo "Import $value successfully! <br>" ;
// $query1 =
// "Delete FROM hklcanet_pha.psr this
// WHERE year(psr.ReportDate) = $input3
// AND month(psr.ReportDate) = $input2";
$query = "load data local infile '//192.168.100.3/Groups/$location1/Timesheet/$value'
replace
into table hklcanet_pha.psr fields terminated by ','
optionally enclosed by '"'
lines terminated by '
'
ignore 1 lines
(`ReportDate`, @dummy, @dummy, `Team_refno`,`Name/Description`,`Status`,`PIC`,`RequestDate`,`TargetEndDate`,`ActualEndDate`,`PlanStartDate`,`ActualStartDate`,`PlanUATDate`,`ActualUATDate`,`PlanImplement`,`ActualImplement` )";
//echo "Import $value successfully! <br>" ;
$result = $connection->query($query) or exit("Error code ({$connection->errno}): {$connection->error}");
}
}
if(sizeof($flag) == 0){
//Display all the file names in alert
$failedFiles = implode(",",$flag);
echo "<script>alert('Import Failed for files : ".$failedFiles."');</script>";
}
unset($value);
?>