24 lines
617 B
PHP
24 lines
617 B
PHP
|
<?php
|
||
|
|
||
|
include('config.php');
|
||
|
|
||
|
if(isset($_FILES['upload'])) {
|
||
|
$extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
|
||
|
$filename = generate_hash($hashlen) . '.' . $extension;
|
||
|
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
|
||
|
|
||
|
echo json_encode(['datadir' => $datadir, 'filename' => $filename]);
|
||
|
}
|
||
|
|
||
|
function generate_hash(int $length) {
|
||
|
$hash = "";
|
||
|
for($i = 0; $i < $length; $i++) {
|
||
|
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||
|
$random_char = $chars[rand(0, strlen($chars) - 1)];
|
||
|
$hash = $hash . $random_char;
|
||
|
}
|
||
|
return $hash;
|
||
|
}
|
||
|
|
||
|
?>
|