Another image question. This small bit of code checks to see if an image exists in the database with the same filename. I've got it set up so that each time it finds something existing, it tacks on 1_ to the beginning of the filename and uploads it. IE myimage.gif to 1_myimage.gif.
Fine, but then I see a problem. If someone uploads myimage.gif again, it would overwrite/reuse 1_myimage.gif. I suppose I would need to have 2_myimage.gif.
What is the solution here? The chance of having duplicates will be slim in this application, but I want to be prepared.
while ($query_row = mysql_fetch_array ($query_image)) {
if ($userfile_name == $query_row['picture']) {
echo "Filename exists. Creating new filename.";
echo " - ";
echo $query_row[picture];
echo "<BR>";
$userfile_name = "1_".$query_row['picture'];
echo "New filename.";
echo " - ";
echo $userfile_name;
echo "<BR>";
}
else {
echo "Uploading image.<br>";
echo "<BR><BR>";
echo $query_image;
//$userfile_name = "default.gif";
}
}