· 8 months ago · Mar 09, 2025, 02:40 PM
1<?php
2/*
3location: ajax/
4*/
5include "../configs/base.php";
6include_once "../functions/_main.php";
7
8if(!isset($folderUpload)){
9 $folderUpload = _SITEDIR_ . "/uploads/";
10 if (!is_dir($folderUpload)) {
11 mkdir($folderUpload);
12 }
13}
14
15$res = [];
16$res["error"] = 1;
17
18if (isset($_POST["params"])) {
19 //$json=openssl_decrypt( $_POST['params'] ,"AES-128-ECB", $password);
20 $json = decryptData($_POST["params"]);
21 $ar = json_decode($json ?? "");
22
23 $res["param"] = $ar;
24 $res["message"] = "upload telah success";
25 $res["html"] = " ";
26 $res["debug"] = [$_FILES, $_POST];
27 $result = 1;
28 //folder
29 $res["debug"][] = "folder:" . $folderUpload;
30 $folderTarget = $ar->folder ?? "example";
31 $tanggalData = $ar->date ?? "2024-12-12";
32 $num = $ar->num ?? "100";
33
34 //filename
35 $aFile = explode(".", $_FILES["file"]["name"] ?? "nofile.tmp");
36 $ext = $aFile[count($aFile) - 1];
37 $filename = $ar->filename ?? "test";
38 $sourceFile = $_FILES["file"]["tmp_name"];
39
40 if ($result == 1) {
41 $targetFile = uploadAttachment(
42 $sourceFile,
43 $folderTarget,
44 $filename,
45 $ext,
46 $tanggalData
47 );
48
49 $imgOnSite =
50 "http://localhost:2082/" . str_replace(__DIR__, "", $targetFile);
51 $time = round(microtime(1) * 1000);
52 $res["html"] .= viewAttachment(
53 $folderTarget,
54 $filename,
55 $tanggalData,
56 $num
57 );
58
59 $res["error"] = 0;
60 }
61 //unset( $res['debug'] );
62}
63
64//$res['error']=1;$res['message']='extension tidak sesuai';
65echo json_encode($res);