54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
|
|
$allowedFileTypes = [
|
|
"doc", "docx", "xls", "xlsx", "pdf",
|
|
"jpeg", "jpg", "gif", "png", "mp3", "zip", "rar"
|
|
];
|
|
|
|
if(isset($_POST['list_id'])){
|
|
$listId = $_POST['list_id'];
|
|
|
|
$type = $_POST['type_file'];
|
|
|
|
if ($type) {
|
|
$type = strtolower($type);
|
|
}
|
|
|
|
if (!$type || !in_array($type, $allowedFileTypes)) {
|
|
$result['res'] = "Неверный тип файла";
|
|
echo json_encode($result);
|
|
exit;
|
|
}
|
|
|
|
$path = $_SERVER['DOCUMENT_ROOT']."/upload/whatsapp";
|
|
|
|
if(!file_exists($path)){
|
|
mkdir($path, 0777);
|
|
}
|
|
|
|
$path = $_SERVER['DOCUMENT_ROOT']."/upload/whatsapp/".$listId;
|
|
|
|
if(!file_exists($path)){
|
|
mkdir($path, 0777);
|
|
}
|
|
|
|
$name = $_FILES['file']['name'];
|
|
|
|
$name = str_replace(" ", "_", $name);
|
|
|
|
$result['guid'] = $name;
|
|
$result['res'] = 'failed';
|
|
|
|
if (move_uploaded_file($_FILES["file"]["tmp_name"], $path . "/" . $name)) {
|
|
$url = "https://joywork.ru" . "/upload/whatsapp/" . $listId . "/" . $name;
|
|
|
|
$sql = "UPDATE whatsapp_list SET url = '$url' WHERE id = $listId";
|
|
mysql_query($sql);
|
|
|
|
$result['res'] = "done";
|
|
echo json_encode($result);
|
|
exit;
|
|
|
|
}
|
|
} |