bluedemon Posted August 15, 2012 Share Posted August 15, 2012 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)) { } ?> Quote Link to comment https://forums.phpfreaks.com/topic/267115-php-help-check-for-an-image/ Share on other sites More sharing options...
MMDE Posted August 15, 2012 Share Posted August 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267115-php-help-check-for-an-image/#findComment-1369593 Share on other sites More sharing options...
bluedemon Posted August 15, 2012 Author Share Posted August 15, 2012 i just want it to see im the same picture is already there even if it is a different name. Quote Link to comment https://forums.phpfreaks.com/topic/267115-php-help-check-for-an-image/#findComment-1369595 Share on other sites More sharing options...
MMDE Posted August 15, 2012 Share Posted August 15, 2012 i just want it to see im the same picture is already there even if it is a different name. I think the best way would be to have some kind of checksum register. http://en.wikipedia.org/wiki/Checksum Quote Link to comment https://forums.phpfreaks.com/topic/267115-php-help-check-for-an-image/#findComment-1369599 Share on other sites More sharing options...
bluedemon Posted August 15, 2012 Author Share Posted August 15, 2012 i will look into it thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/267115-php-help-check-for-an-image/#findComment-1369603 Share on other sites More sharing options...
bluedemon Posted August 15, 2012 Author Share Posted August 15, 2012 Is there any easier way than using checksum or using the code above could you add the code to it Quote Link to comment https://forums.phpfreaks.com/topic/267115-php-help-check-for-an-image/#findComment-1369632 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.