2023-03-22 23:10:33 +01:00
|
|
|
<?php
|
|
|
|
|
2023-03-23 11:15:05 +01:00
|
|
|
if(is_file('config.php')) {
|
|
|
|
include('config.php');
|
|
|
|
} else {
|
|
|
|
include('config.dist.php');
|
|
|
|
}
|
2023-03-22 23:10:33 +01:00
|
|
|
|
2023-03-23 00:26:41 +01:00
|
|
|
if(!is_dir($datadir)) {
|
|
|
|
mkdir($datadir);
|
|
|
|
}
|
|
|
|
|
2023-03-22 23:10:33 +01:00
|
|
|
if(isset($_FILES['upload'])) {
|
|
|
|
$extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
|
2023-03-23 20:03:42 +01:00
|
|
|
$extension = strtolower($extension);
|
2023-03-23 11:15:05 +01:00
|
|
|
|
2023-03-22 23:16:47 +01:00
|
|
|
if($extension == 'jpg' || $extension == 'jpeg' || $extension == 'png') {
|
2023-03-23 07:41:12 +01:00
|
|
|
$filename = generate_filename($length) . '.' . $extension;
|
2023-03-22 23:16:47 +01:00
|
|
|
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
|
|
|
|
echo json_encode(['datadir' => $datadir, 'filename' => $filename]);
|
|
|
|
}
|
2023-03-22 23:10:33 +01:00
|
|
|
}
|
|
|
|
|
2023-03-23 07:41:12 +01:00
|
|
|
function generate_filename($length) {
|
|
|
|
$filename = "";
|
2023-03-23 11:15:05 +01:00
|
|
|
|
2023-03-22 23:10:33 +01:00
|
|
|
for($i = 0; $i < $length; $i++) {
|
|
|
|
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
$random_char = $chars[rand(0, strlen($chars) - 1)];
|
2023-03-23 07:41:12 +01:00
|
|
|
$filename = $filename . $random_char;
|
2023-03-22 23:10:33 +01:00
|
|
|
}
|
2023-03-23 11:15:05 +01:00
|
|
|
|
2023-03-23 07:41:12 +01:00
|
|
|
return $filename;
|
2023-03-22 23:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|