#!/usr/bin/php array(), 'message' => array()); foreach (glob($path.'/*') as $file) { // Get the file names only, the path is known anyway $filename = basename($file); if (!in_array($filename, $oldfiles)) { // Create separate messages for files and directories if (is_file($file)) { $newfiles['filename'][] = $filename; $newfiles['message'][] = sprintf('Datei: %s [%01.2f KB]', $filename, (filesize($file) / 1024)); } elseif (is_dir($file)) { $newfiles['filename'][] = $filename; $newfiles['message'][] = 'Verzeichnis: '.$filename; } } else { // Delete this file from the list of removed files unset($removed_files[array_search($filename, $removed_files)]); } } // Delete the removed files from the old files array $oldfiles = array_diff($oldfiles, $removed_files); $num_newfiles = count($newfiles['filename']); $files_list = implode(LF, array_merge($oldfiles, $newfiles['filename'])); // Write all existing file names to the file that holds the list of already existing files file_put_contents($checkfile_path, $files_list, LOCK_EX); if ($num_newfiles > 0) { $newfiles_messages_list = implode(LF, $newfiles['message']); // Send the e-mail $mailtext = 'Hallo,'.LF.LF. 'es sind neue Daten im Kunden-Ordner platziert worden.'.LF.LF. 'Gesamtanzahl: '.$num_newfiles.LF.LF. $newfiles_messages_list; mail($empfaenger, $betreff, $mailtext, $header); } echo $num_newfiles.' neue Dateien/Verzeichnisse gefunden!'; ?>