PHP 8.4.24 Released!

Voting

: three minus three?
(Example: nine)

The Note You're Voting On

schiros at invisihosting dot com
18 years ago
If you've got a script that allows user file upload, and you want to prevent multiple uploads of the same file:

    <?
        session_start();
        $isDuplicate = false;
        if(isset($_FILES["filename"]["tmp_name"]) && file_exists($_FILES["filename"]["tmp_name"])) {
            $fileHash = sha1_file($_FILES["filename"]["tmp_name"]);
            if(!isset($_SESSION["check_filelist"])) {
                $_SESSION["check_filelist"] = array($fileHash);
            }
            elseif(in_array($fileHash,$_SESSION["check_filelist"])) {
                $isDuplicate = true;    
            }
            else {
                $_SESSION["check_filelist"][] = $fileHash;    
            }
            
            if($isDuplicate) {
                echo "You've already uploaded that file";    
            }
            else{
                // do some stuff    
            }
        }
        
    ?>

<< Back to user notes page

To Top