Jump to content

PHP HELP check for an image


bluedemon

Recommended Posts

hello the following script i am using to upload pictures to my site can anyone help me make it check if the image exists and if it does tell the user that the picture is already there.

<?php
$uploaddir = './';      //Uploading to same directory as PHP file

$file = basename($_FILES['userfile']['name']);

$uploadFile = $file;
$randomNumber = rand(0, 9999999999999);

$newName = $uploadDir . $randomNumber . $uploadFile;

if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
    echo "Temp file uploaded.";
} else {
    echo "Temp file not uploaded.";
}

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) {

}
?>

Link to comment
https://forums.phpfreaks.com/topic/267115-php-help-check-for-an-image/
Share on other sites

Isn't it just to check if there is an image with the same name in the directory you want to upload it to?

Or do you want to check if the image might already be there but under another name?

 

Maybe creating a register of the various images hash checksums would do the trick in this case, but I'm not sure how it would handle the different meta data. At least you can check if the exact same image exists already, and if it's not the exact same image you could make it a new name, but remember to store it's old hash check sum.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.