I tried it with if exists on sql but it says error.
if (isset($_POST['ReScan'])){
$dateien = 'dateien/';
$directoryscanarray = scandir($dateien);
print_r($directoryscanarray);
$arrlength = count($directoryscanarray);
for($x = 2; $x < $arrlength; $x++) {
$foldername = $directoryscanarray[$x];
$sql = "INSERT INTO localfiles (foldername) VALUES ('$foldername')";
maybe:
WHERE NOT EXISTS SELECT foldername FROM localfiles WHERE name='$foldername'";
You could try this (not tested):
$sql = " INSERT INTO localfiles (foldername) VALUES ('$foldername') ON DUPLICATE KEY UPDATE field_1="value_1", field_2="value_2" WHERE foldername='$foldername'";
You can make the foldername an unique key and use
INSERT INTO ... ON DUPLICATE KEY UPDATE ...
Where on duplicate key you would just say the key equals itself
http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html