"Hash" umbenannt weil gar kein Hash

This commit is contained in:
root 2023-03-23 06:41:12 +00:00
parent 4f95661b3b
commit e6fba1ef7b
2 changed files with 6 additions and 6 deletions

View File

@ -10,6 +10,6 @@ $text = "Click or drop image here...";
$datadir = "i";
// Length of filenames
$hashlen = 8;
$length = 8;
?>

View File

@ -9,20 +9,20 @@ if(!is_dir($datadir)) {
if(isset($_FILES['upload'])) {
$extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
if($extension == 'jpg' || $extension == 'jpeg' || $extension == 'png') {
$filename = generate_hash($hashlen) . '.' . $extension;
$filename = generate_filename($length) . '.' . $extension;
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
echo json_encode(['datadir' => $datadir, 'filename' => $filename]);
}
}
function generate_hash(int $length) {
$hash = "";
function generate_filename($length) {
$filename = "";
for($i = 0; $i < $length; $i++) {
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$random_char = $chars[rand(0, strlen($chars) - 1)];
$hash = $hash . $random_char;
$filename = $filename . $random_char;
}
return $hash;
return $filename;
}
?>