Сглобих един готов код който БИ ТРЯБВАЛО да чете файловете от директория, да взима имената им в масив и после да прави проверка дали файловете (имената им) вече съществуват във база данни, и ако не съществуват да ги запише,но не се получава...
$filez държи имената
и сега проверката:
Но като добавя нови файлове не се записват просто нищо не изписва... явно някъде има проблем в кода.
пс:Опитах със print_r($filez); и показва всички имена както си трябва...
:lol:
Код:
//open dir and get file names
$directoryy="mydir";
// create a handler to the directory
$dirhandler = opendir($directoryy);
// read all the files from directory
$nofiles=0;
while ($filee = readdir($dirhandler)) {
// if $file isn't this directory or its parent
//add to the $files array
if ($filee != '.' && $filee != '..')
{
$nofiles++;
$filez[$nofiles]=$filee;
}
}
и сега проверката:
Код:
//check if file exist
$item_exists_sql = "SELECT name FROM pictures where name = '" . $filez . "'";
$item_exists = mysql_query($item_exists_sql, $db);
if(mysql_num_rows($item_exists)<1)
{
echo "<font color=green>Inserting new item...</font><br/>";
$item_insert_sql = "INSERT INTO pictures(name, title) VALUES ('" . $filez . "','1')";
$insert_item = mysql_query($item_insert_sql, $db) or die (mysql_error());
if (!$insert_item) { echo"we have a problem";}
}
else
{
echo "";//<font color=blue>Not inserting existing item..</font><br/>
}
пс:Опитах със print_r($filez); и показва всички имена както си трябва...
:lol: