341 lines
11 KiB
PHP
341 lines
11 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['funnel_id'])){
|
|
$funnel_id = $_POST['funnel_id'];
|
|
$etap_id = 'temp';
|
|
if(isset($_POST['etap_id'])){
|
|
$etap_id = $_POST['etap_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/funnels/".$funnel_id;
|
|
$name = md5(time().$_FILES['file']['name'].$_FILES['file']['size']);
|
|
$result['guid'] = $name;
|
|
$result['res'] = 'failed';
|
|
if(!file_exists($path)){
|
|
mkdir($path, 0777);
|
|
}
|
|
$sql_f = "SELECT id FROM funnel_files WHERE guid = '{$name}' and funnel_id = '{$funnel_id}' and etap_id = '{$etap_id}'";
|
|
$q_f = mysql_query($sql_f);
|
|
if(mysql_num_rows($q_f) == 0){
|
|
$sql = "INSERT INTO funnel_files (guid, funnel_id, type, name) VALUES ('{$name}', '{$funnel_id}', '{$type}', '{$_FILES['file']['name']}')";
|
|
|
|
if(!file_exists($path."/".$name.".".$type)){
|
|
if (move_uploaded_file($_FILES["file"]["tmp_name"], $path."/".$name.".".$type)) {
|
|
mysql_query($sql);
|
|
|
|
//отправляем файл в Селектел
|
|
$token = SelectelApi::getNewToken();
|
|
|
|
$contType = "application/octet-stream";
|
|
|
|
if ($type) {
|
|
$type = strtolower($type);
|
|
}
|
|
|
|
if ($type === "doc") {
|
|
$contType = "application/msword";
|
|
}
|
|
if ($type === "docx") {
|
|
$contType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
}
|
|
if ($type === "xls") {
|
|
$contType = "application/vnd.ms-excel";
|
|
}
|
|
if ($type === "xlsx") {
|
|
$contType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
}
|
|
if ($type === "pdf") {
|
|
$contType = "application/pdf";
|
|
}
|
|
if ($type === "jpeg" || $type === "jpg") {
|
|
$contType = "image/jpeg";
|
|
}
|
|
if ($type === "gif") {
|
|
$contType = "image/gif";
|
|
}
|
|
if ($type === "png") {
|
|
$contType = "image/png";
|
|
}
|
|
if ($type === "mp3") {
|
|
$contType = "audio/mpeg";
|
|
}
|
|
if ($type === "zip") {
|
|
$contType = "application/zip";
|
|
}
|
|
if ($type === "rar") {
|
|
$contType = "application/vnd.rar";
|
|
}
|
|
|
|
$new_path = "/upload/funnels/". $funnel_id . "/" . $name . '.' . $type;
|
|
|
|
$r = SelectelApi::uploadUserFile($token, $path . "/" . $name . "." . $type, $new_path, $contType);
|
|
|
|
$result['sel'] = $r;
|
|
|
|
$result['res'] = "done";
|
|
echo json_encode($result);
|
|
exit;
|
|
|
|
}
|
|
} else {
|
|
$result['res'] = "done";
|
|
echo json_encode($result);
|
|
exit;
|
|
}
|
|
} else {
|
|
$result['res'] = "done";
|
|
echo json_encode($result);
|
|
exit;
|
|
}
|
|
exit();
|
|
}
|
|
|
|
if(isset($_POST['client_id'])){
|
|
$client_id = $_POST['client_id'];
|
|
$reqId = 0;
|
|
if(isset($_POST['req_id'])){
|
|
$reqId = (int)$_POST['req_id'];
|
|
}
|
|
$etap_id = $_POST['etap_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/funnels/clients/".$client_id;
|
|
if($reqId > 0){
|
|
$path = $_SERVER['DOCUMENT_ROOT']."/upload/funnels/req/".$reqId;
|
|
}
|
|
$name = md5(time().$_FILES['file']['name'].$_FILES['file']['size']."clients".$client_id);
|
|
if($reqId > 0){
|
|
$name = md5(time().$_FILES['file']['name'].$_FILES['file']['size']."clients".$reqId);
|
|
}
|
|
$result['guid'] = $name;
|
|
$result['res'] = 'failed';
|
|
if(!file_exists($path)){
|
|
mkdir($path, 0777);
|
|
}
|
|
|
|
$sql_f = "SELECT id FROM funnel_files WHERE guid = '{$name}' and client_id = '{$client_id}' and etap_id = '{$etap_id}'";
|
|
if($reqId > 0){
|
|
$sql_f = "SELECT id FROM funnel_files WHERE guid = '{$name}' and req_id = '{$reqId}' and etap_id = '{$etap_id}'";
|
|
}
|
|
//echo $sql_f;
|
|
$q_f = mysql_query($sql_f);
|
|
if(mysql_num_rows($q_f) == 0){
|
|
$sql = "INSERT INTO funnel_files (guid, client_id, type, name, etap_id) VALUES ('{$name}', '{$client_id}', '{$type}', '{$_FILES['file']['name']}', '{$etap_id}')";
|
|
if($reqId > 0){
|
|
$sql = "INSERT INTO funnel_files (guid, req_id, type, name, etap_id) VALUES ('{$name}', '{$reqId}', '{$type}', '{$_FILES['file']['name']}', '{$etap_id}')";
|
|
|
|
}
|
|
|
|
if(!file_exists($path."/".$name.".".$type)){
|
|
if (move_uploaded_file($_FILES["file"]["tmp_name"], $path."/".$name.".".$type)) {
|
|
mysql_query($sql);
|
|
|
|
//отправляем файл в Селектел
|
|
$token = SelectelApi::getNewToken();
|
|
|
|
$contType = "application/octet-stream";
|
|
|
|
if ($type) {
|
|
$type = strtolower($type);
|
|
}
|
|
|
|
if ($type === "doc") {
|
|
$contType = "application/msword";
|
|
}
|
|
if ($type === "docx") {
|
|
$contType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
}
|
|
if ($type === "xls") {
|
|
$contType = "application/vnd.ms-excel";
|
|
}
|
|
if ($type === "xlsx") {
|
|
$contType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
}
|
|
if ($type === "pdf") {
|
|
$contType = "application/pdf";
|
|
}
|
|
if ($type === "jpeg" || $type === "jpg") {
|
|
$contType = "image/jpeg";
|
|
}
|
|
if ($type === "gif") {
|
|
$contType = "image/gif";
|
|
}
|
|
if ($type === "png") {
|
|
$contType = "image/png";
|
|
}
|
|
if ($type === "mp3") {
|
|
$contType = "audio/mpeg";
|
|
}
|
|
if ($type === "zip") {
|
|
$contType = "application/zip";
|
|
}
|
|
if ($type === "rar") {
|
|
$contType = "application/vnd.rar";
|
|
}
|
|
|
|
|
|
$new_path = "/upload/funnels/clients/" . $client_id . "/" . $name . '.' . $type;
|
|
|
|
if($reqId > 0) {
|
|
$new_path = "/upload/funnels/req/" . $reqId . "/" . $name . '.' . $type;
|
|
}
|
|
|
|
$r = SelectelApi::uploadUserFile($token, $path . "/" . $name . "." . $type, $new_path, $contType);
|
|
|
|
$result['sel'] = $r;
|
|
|
|
$result['res'] = "done";
|
|
echo json_encode($result);
|
|
exit;
|
|
|
|
}
|
|
} else {
|
|
$result['res'] = "done";
|
|
echo json_encode($result);
|
|
exit;
|
|
}
|
|
} else {
|
|
$result['res'] = "done";
|
|
echo json_encode($result);
|
|
exit;
|
|
}
|
|
exit();
|
|
}
|
|
|
|
if(isset($_POST['funnel_id_prev'])){
|
|
|
|
/*error_reporting(E_ALL | E_STRICT);
|
|
ini_set('display_errors', 1);*/
|
|
$funnel_id = $_POST['funnel_id_prev'];
|
|
//$step_id = $_POST['file_prev'];
|
|
$etap_id = 'temp';
|
|
if(isset($_POST['etap_id'])){
|
|
$etap_id = $_POST['etap_id'];
|
|
}
|
|
$type = $_POST['type_file'];
|
|
|
|
if ($type) {
|
|
$type = strtolower($type);
|
|
}
|
|
|
|
if (!$type || !in_array($type, $allowedFileTypes)) {
|
|
$result['res'] = "Неверный тип файла";
|
|
echo json_encode($result);
|
|
exit;
|
|
}
|
|
|
|
if(!file_exists($_SERVER['DOCUMENT_ROOT']."/upload/funnels/prev_steps")){
|
|
mkdir($_SERVER['DOCUMENT_ROOT']."/upload/funnels/prev_steps", 0777);
|
|
}
|
|
$path = $_SERVER['DOCUMENT_ROOT']."/upload/funnels/prev_steps/".$funnel_id;
|
|
$name = md5(time().$_FILES['file']['name'].$_FILES['file']['size']);
|
|
$result['guid'] = $name;
|
|
$result['res'] = 'failed';
|
|
if(!file_exists($path)){
|
|
mkdir($path, 0777);
|
|
}
|
|
/*$sql_f = "SELECT id FROM files_steps_funnel_prev WHERE guid = '{$name}' and funnel_id = '{$funnel_id}' and step_id = '{$etap_id}'";
|
|
$q_f = mysql_query($sql_f);*/
|
|
// if(mysql_num_rows($q_f) == 0){
|
|
$sql = "INSERT INTO files_steps_funnel_prev (guid, funnel_id, type, name) VALUES ('{$name}', '{$funnel_id}', '{$type}', '{$_FILES['file']['name']}')";
|
|
|
|
if(!file_exists($path."/".$name.".".$type)){
|
|
if (move_uploaded_file($_FILES["file"]["tmp_name"], $path."/".$name.".".$type)) {
|
|
mysql_query($sql);
|
|
$id_in = mysql_insert_id();
|
|
$result['res'] = "done";
|
|
$result['id'] = $id_in;
|
|
|
|
//отправляем файл в Селектел
|
|
$token = SelectelApi::getNewToken();
|
|
|
|
$contType = "application/octet-stream";
|
|
|
|
if ($type) {
|
|
$type = strtolower($type);
|
|
}
|
|
|
|
if ($type === "doc") {
|
|
$contType = "application/msword";
|
|
}
|
|
if ($type === "docx") {
|
|
$contType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
}
|
|
if ($type === "xls") {
|
|
$contType = "application/vnd.ms-excel";
|
|
}
|
|
if ($type === "xlsx") {
|
|
$contType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
}
|
|
if ($type === "pdf") {
|
|
$contType = "application/pdf";
|
|
}
|
|
if ($type === "jpeg" || $type === "jpg") {
|
|
$contType = "image/jpeg";
|
|
}
|
|
if ($type === "gif") {
|
|
$contType = "image/gif";
|
|
}
|
|
if ($type === "png") {
|
|
$contType = "image/png";
|
|
}
|
|
if ($type === "mp3") {
|
|
$contType = "audio/mpeg";
|
|
}
|
|
if ($type === "zip") {
|
|
$contType = "application/zip";
|
|
}
|
|
if ($type === "rar") {
|
|
$contType = "application/vnd.rar";
|
|
}
|
|
|
|
$new_path = "/upload/funnels/prev_steps/". $funnel_id . "/" . $name . '.' . $type;
|
|
|
|
$r = SelectelApi::uploadUserFile($token, $path . "/" . $name . "." . $type, $new_path, $contType);
|
|
|
|
$result['sel'] = $r;
|
|
|
|
echo json_encode($result);
|
|
exit;
|
|
|
|
}
|
|
} else {
|
|
$result['res'] = "done";
|
|
echo json_encode($result);
|
|
exit;
|
|
}
|
|
|
|
/* } else {
|
|
$result['res'] = "done";
|
|
echo json_encode($result);
|
|
exit;
|
|
}*/
|
|
exit();
|
|
} |