Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.