Advertisement
kura2yamato

uploadFile.php

Mar 9th, 2025
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | Source Code | 0 0
  1. <?php
  2. /*
  3. location: ajax/
  4. */
  5. include "../configs/base.php";
  6. include_once "../functions/_main.php";
  7.  
  8. if(!isset($folderUpload)){
  9.     $folderUpload = _SITEDIR_ . "/uploads/";
  10.     if (!is_dir($folderUpload)) {
  11.         mkdir($folderUpload);
  12.     }
  13. }
  14.  
  15. $res = [];
  16. $res["error"] = 1;
  17.  
  18. if (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';
  65. echo json_encode($res);
Tags: php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement