현재이 데이터베이스를 실행하면 데이터베이스에있는 이미지 데이터가 복제 될 수있는 문제가 발생합니다. 예를 들어 업로드 파일에 5 개의 이미지를 업로드 한 다음 스크립트를 클릭하면 모든 것이 잘됩니다. 다른 이미지를 추가하고 스크립트를 다시 클릭하면 데이터베이스에있는 6 개의 이미지가 11 개가되었습니다.이 문제를 해결할 수 있도록 내 코드를 어떻게 수정할 수 있는지 궁금합니다.파일의 데이터가 이미 데이터베이스에 있는지 확인하는 방법
include('mysql.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."')";
}
}
closedir($handle);
}
/* insert new record into the table images with the filename */
$query = "INSERT INTO images (filename) VALUES ".implode(',', $images)." ";
if (!mysql_query($query)) {
print mysql_error();
}
else {
print "finished installing your images!";
}
당신이 만들 수있는'filename''UNIQUE'는 단지 새로운, 독특한, 파일 이름이 추가됩니다. – Sean
한 문자열에 여러 이미지를 삽입하여 한 행에 이미지를 삽입하면 정확히 필요합니까? 데이터베이스의 각 이미지에 대해 1 행을 작성하여 중복을 방지 할 수 있습니까? – MaveRick