/** * block */ function saveImportAntiSpamIp($post) { ExtraWatchInput::validate(_EW_INPUT_FILE_NAME, $_FILES); if ($_FILES["file"]["type"] == "application/octet-stream") { /// if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; return; } } if (!ExtraWatchHelper::endsWith($_FILES["file"]["name"], ".csv")) { echo _EW_ANTISPAM_INVALID_EXTENSION; return; } $uploadedFilePath = JPATH_BASE . "/" . $_FILES["file"]["name"]; /// move_uploaded_file($_FILES["file"]["tmp_name"], $uploadedFilePath); /// set_time_limit(0); $handle = fopen($uploadedFilePath, "r"); if (!$handle) { return "Error: it was not possible to open uploaded file from: " . $uploadedFilePath; } $errorMessages = array(); $i = 0; while (($data = stream_get_line($handle, 1024, ",")) !== FALSE) { $ip = $data; if ($ip != 'ip') { if (!ExtraWatchHelper::isValidIPv4($ip)) { $errorMessages[] = "{$ip} is not a valid IP address!"; continue; } $ipArray[] = $ip; } if ($i % self::IP_BULK_IMPORT_SIZE == self::IP_BULK_IMPORT_SIZE - 1) { //flushing array when it has particular size to DB $this->flushIPBulkFromArray($ipArray); $ipArray = array(); } $i++; } $this->flushIPBulkFromArray($ipArray); fclose($handle); unlink($uploadedFilePath); return implode("\n", $errorMessages); }