Adding images to database

I have a script that I use to add images filenames to a mysql database.

The script I created, however, is not doing exactly what I want and I do not know how to make it do so.

I want the script to only insert NEW images, when I run it. It currently inserts all images, even if they already exist. It just gives them a new image_id [the id of the row in database].

Could anyone help? [php]<?php


if ($handle = opendir(‘images’)) {

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
	if($file!='.' && $file!='..') {
		$images[] = "('".$file."')";



$query = "INSERT INTO images (filename) VALUES “.implode(’,’, $images).” ";
if (!mysql_query($query)) {
print mysql_error();
else {
print “finished installing images!”;


Sponsor our Newsletter | Privacy Policy | Terms of Service