"Hash" umbenannt weil gar kein Hash
This commit is contained in:
parent
4f95661b3b
commit
e6fba1ef7b
|
@ -10,6 +10,6 @@ $text = "Click or drop image here...";
|
|||
$datadir = "i";
|
||||
|
||||
// Length of filenames
|
||||
$hashlen = 8;
|
||||
$length = 8;
|
||||
|
||||
?>
|
||||
|
|
10
upload.php
10
upload.php
|
@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue