PHP 8.5.0 Alpha 2 available for testing

Voting

: min(one, two)?
(Example: nine)

The Note You're Voting On

schiros at invisihosting dot com
17 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