Hi, I have made a script that scans a folder for pictures and then is supposed to insert the pictures into a database but it isnt inserting the data and I dont know why. Here is the code I am using:
PHP Code:
<?
$host="*****"; // Host name
$username="*****"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
$tbl_name="*****"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$files = array();
// Define the full path to the folder whose contents you want to list
$path = ".";
//File Types allowed
$pattern="\.(jpg|jpeg|png|gif|bmp)$";
// Open the directory
$dir_handle = @opendir($path) or die("Error opening $path");
// Loop through the files
while ($file = readdir($dir_handle)) {
if(eregi($pattern, $file))
//Prints the pictures
echo "<a href=\"$file\">$file</a><br />";
$sql="INSERT INTO $tbl_name (file_name, path_-_large, path_-_thumbnail)VALUES('$file', 'http://www.calumogg.co.uk/landscapes/thumbs/$file', 'http://www.calumogg.co.uk/landscapes/thumbs/$file')";
$result=mysql_query($sql);
}
// Close
closedir($dir_handle);
?>
It is printing the pictures fine, but nothing else. Any Help would be greatly appreciated.
Bookmarks