each user uploads images to my website using php. sometimes they spam the exact same image dozens of times which drives me nuts.
i am adding a column in the SQL db to add the md5 hash of every image they upload to prevent repeat uploads. let's call this column 'md5_images'.
when's a file is uploaded, i'd like json_decode all the previously user uploaded image md5s and if they are in_array(), i alert them that the image has already been uploaded by them (the logged in user). if it is a new image, i add the md5 hash to the end of the uploaded md5 image array and update the image_md5 column for that user and then upload their image.
my issue is that I cannot figure out an elegant wait to do this without adding each md5 hash with a space between them (e.g; md5_1 md_2 md5_3) and then turning that row of md5 s by explode() the column by spaces to get the array list to compare the newly uploaded user image md5 to.
$images = mysqli_query($conn, 'SELECT md5_images FROM table WHERE user = "example"');
if(mysqli_num_rows($images) > 0) {
$images = mysqli_fetch_assoc($images);
$check_md5s = json_decode($results['md5_examples'];
}
if(in_array(md5($file), $check_md5s)) {
//don't upload;
} else {
foreach($results['md5_examples'] as $example) {
$arr[] = $example;
}
$arr[] = md5($file);
$update = json_encode($arr)(
then update user column with new
$update of uploaded image md5 hashes
for later checks.
}
if the user has no images uploaded already, the obviously allow it to be uploaded and add the md5 hash to the list for later incase they want to upload more.
is there a simpler/more professional way to do this?
each user has their own set of files they can't reupload, it's not the entire website that refuses any duplicates whatsoever.
can anyone else me with this?