我尝试编写常规循环,但到目前为止我尝试过的所有解决方案都会产生错误。
这两种:
$length = count($fileList);
for ($index = 0; $index < $length; $index++) {
和
for ($index = 0, $length = count($fileList); $index <= $length; $index++) {
生成以下错误(在编译时):
Parse error: syntax error, unexpected '$length' (T_VARIABLE), expecting ';' in C:\xampp\htdocs\PC_administration_interface\Controler\Interface_builder\html\html_data_importer.php on line 590
如果我试试这个:
for ($index = 0; $index < count($fileList); $index++) {
然后,我收到此错误(在运行时):
Fatal error: Call to undefined function count() in C:\xampp\htdocs\PC_administration_interface\Controler\Interface_builder\html\html_data_importer.php on line 590
即便如此:
for ($index = 0; $index < 1; $index++) {
给我以下错误(在运行时):
Use of undefined constant 1 - assumed ' 1'
到目前为止,这是完整的背景:
/**
* In $fileList, validate the files (name and extension) and save the files related to the import.
* If a file already exists for a specific import, it will be replaced by the new one.
*
* @param $errorMessage String to return the error message.
* @param $fileList Array containing the files to upload. Use $_FILES[] and send the array of the upload button.
* @param $dataSource Int Use DataSupport class constant
* @param $cleanList Boolean clean the current list.
*/
public function saveSourceFileList(&$errorMessage, array $fileList, $dataSource, $cleanList = false){
$errorMessage = "";
$fileArray = array();
$invalidArray = array();
$path = realpath(dirname(__FILE__)) . '/../../Backup/';
if (!empty($fileList)){
$length = count($fileList);
for ($index = 0; $index < $length; $index++) {
if ($this->importer->isFileToImportValid($fileList['name'][$index], $dataSource)){
$name = substr_replace($fileList['name'][$index], date("Ymd_His"), (strpos($fileList['name'][$index], ".")), 0);
echo $name;
$fileArray[] = "";
}
else{
$invalidArray[] = $fileList['name'][$index];
}
}
}
}