39 lines
883 B
PHP
39 lines
883 B
PHP
<?php
|
|
|
|
if(is_file('config.php')) {
|
|
include('config.php');
|
|
} else {
|
|
include('config.dist.php');
|
|
}
|
|
|
|
if(!is_dir($datadir)) {
|
|
mkdir($datadir);
|
|
}
|
|
|
|
$extensions = ['jpg', 'jpeg', 'png', 'gif'];
|
|
|
|
if(isset($_FILES['upload'])) {
|
|
$extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
|
|
$extension = strtolower($extension);
|
|
|
|
if(in_array($extension, $extensions)) {
|
|
$filename = generate_filename($length) . '.' . $extension;
|
|
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
|
|
echo json_encode(['datadir' => $datadir, 'filename' => $filename]);
|
|
}
|
|
}
|
|
|
|
function generate_filename($length) {
|
|
$filename = "";
|
|
|
|
for($i = 0; $i < $length; $i++) {
|
|
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$random_char = $chars[rand(0, strlen($chars) - 1)];
|
|
$filename = $filename . $random_char;
|
|
}
|
|
|
|
return $filename;
|
|
}
|
|
|
|
?>
|