Hello!
I have this script that gets the name of all jpegs in a directory then passes the name along with other information into a database.
With the exception of $image_name all variables are being passed correctly to a new record. However the field for $image_name is always blank even though $image_name echos the file name perfectl!
I've tried both text and varchar for the mySQL field type and neither works.
Any ideas would be appreciated!
Thanks, Chris
$add_image = "INSERT INTO $table values('$d','$event_num','$image_name',
'$image_path','$thumb_path')";
//Checks that event image directory exists
if (!(file_exists($event_dir))){
echo '<p>***ERROR*** The directory for event #' . $event_num . ' is not present. Please ensure that the file has been uploaded to the
/images/event_images directory and that it has been named correctly.</p><br />';
echo '<p>' . 'Click here to return to ' . '<a href=../../admin_tools.php>' . 'Administrative tools.</a></p>';
exit();
}
//Gets file name of image
//Checks to make sure it's a jpeg
//If it's a jpeg then it adds it to the database
else{
$open_dir = opendir($event_dir);
while(false !== ($image_name = readdir($open_dir))){
if (is_file($event_dir . '/' . $image_name)){
$file_ext = substr($image_name, -4);
if($file_ext == '.jpg' || 'jpeg' || '.JPG' || 'JPEG'){
echo $image_name . '<br />';
mysql_query($add_image) or die (mysql_error());
} else {
echo 'There were no jpeg images found in the EVENT_' . $event_num . ' directory.';
}
}
}
}