Advertisement
kura2yamato

upload ajax

Mar 9th, 2025 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.82 KB | Source Code | 0 0
  1. <?php
  2. /*
  3. location: /
  4. */
  5. include "configs/base.php";
  6. include_once "functions/_main.php";
  7. echo "<div>RUN :".date("d/m/y H:i:s")."</div>";
  8.  
  9. $ar = [
  10. "folder" => "comic/100",
  11. "filename" => "他の世界", //sensitive
  12. "allows" => ["jpg", "png", "pdf", "画像"], //allowed
  13. //'date'=>"2025-01-25"
  14. ];
  15.  
  16. $string_to_encrypt = json_encode($ar);
  17.  
  18. $encrypted_string = encryptData($string_to_encrypt);
  19. divImageAjax("upload 2 folder (lama)", $encrypted_string);
  20.  
  21. $ar = [
  22.     "folder" => "comic/100",  
  23.     "filename" => "他の世界", //sensitive
  24.     "allows" => ["jpg", "png", "pdf", "画像"], //allowed
  25.     "date" => "2025-01-25", //data date
  26.     "num" => "002",
  27. ];
  28.  
  29. $string_to_encrypt = json_encode($ar);
  30. $encrypted_string = encryptData($string_to_encrypt);
  31.  
  32. ?>
  33. <div>upload 2 folder (baru)
  34. <input type='file' id='fileAjax002' param='<?=$encrypted_string
  35. ?>' />
  36. <button type='button' onclick='saveFile("002")'>Upload</button><br/>
  37. <span id='infoFileAjax002'>
  38. <?=viewAttachment($ar["folder"], $filename = $ar["filename"], $tanggalData = $ar["date"], "002") ?>
  39. </span>
  40. </div>
  41. <div>folder: comicZ</div>
  42. <?php
  43. //----------1 folder------------
  44. $ar = [
  45.     "folder" => "comicZ",  
  46.     "filename" => "他の世界", //sensitive
  47.     "allows" => ["jpg", "png", "pdf", "画像"], //allowed
  48.     "date" => "2025-01-25", //data date
  49. ];
  50. $string_to_encrypt = json_encode($ar);
  51. $encrypted_string = encryptData($string_to_encrypt);
  52. divImageAjax("upload 1 folder (baru)", $encrypted_string);
  53. $ar["filename"] = "1";
  54. $string_to_encrypt = json_encode($ar);
  55. $encrypted_string = encryptData($string_to_encrypt);
  56. divImageAjax("upload 1 folder (baru)", $encrypted_string);
  57. $ar["filename"] = "2";
  58. $string_to_encrypt = json_encode($ar);
  59. $encrypted_string = encryptData($string_to_encrypt);
  60. divImageAjax("upload 1 folder (baru)", $encrypted_string);
  61. unset($ar["date"]);
  62. $string_to_encrypt = json_encode($ar);
  63. $encrypted_string = encryptData($string_to_encrypt);
  64. divImageAjax("upload 1 folder tanpa tanggal (lama)", $encrypted_string);
  65. $ar["filename"] = "他の世界";
  66. $string_to_encrypt = json_encode($ar);
  67. $encrypted_string = encryptData($string_to_encrypt);
  68. divImageAjax("upload 1 folder (lama)", $encrypted_string);
  69. ?>
  70. <div>Folder: comicZ/101</div>
  71. <?php
  72. $ar = [
  73.     "folder" => "comicZ/101",  
  74.     "filename" => "10", //sensitive
  75.     "allows" => ["jpg", "png", "pdf", "画像"], //allowed
  76.     "date" => "2025-01-25", //data date
  77. ];
  78. $string_to_encrypt = json_encode($ar);
  79. $encrypted_string = encryptData($string_to_encrypt);
  80. divImageAjax("upload 1 folder (baru)", $encrypted_string);
  81. $ar["filename"] = "11";
  82. $string_to_encrypt = json_encode($ar);
  83. $encrypted_string = encryptData($string_to_encrypt);
  84. divImageAjax("upload 1 folder (baru)", $encrypted_string);
  85. $ar["filename"] = "20";
  86. unset($ar["date"]);
  87. $string_to_encrypt = json_encode($ar);
  88. $encrypted_string = encryptData($string_to_encrypt);
  89. divImageAjax("upload 1 folder tanpa tanggal (lama)", $encrypted_string);
  90. $ar["filename"] = "21";
  91. $string_to_encrypt = json_encode($ar);
  92. $encrypted_string = encryptData($string_to_encrypt);
  93. divImageAjax("upload 1 folder tanpa tanggal (lama)", $encrypted_string);
  94. ?>
  95. <script>
  96. function downloadFile(params){
  97. var form = document.createElement("form");
  98. var element1 = document.createElement("input");
  99.     form.method = "POST";
  100.     form.action = "ajax/viewFile.php";
  101.     form.target = "baru";
  102.     element1.value=params;
  103.     element1.name="params";
  104.     form.appendChild(element1);  
  105.     document.body.appendChild(form);
  106.  
  107.     form.submit();
  108.     form.remove();
  109. }
  110.  
  111. function deleteFile(num, params){
  112.     if( confirm("Are you want to delete file?") ){
  113.         deleteFileAction(num, params);
  114.     }
  115.     return false;
  116. }
  117.  
  118. async function deleteFileAction(num, params){
  119.  let formData = new FormData();
  120.  var infoDelete=-1;
  121.  let nameViewObj = "infoFileAjax" + num;
  122.     var objViewAjax = document.getElementById(nameViewObj);
  123.  try {
  124.   (async () => {
  125.    formData.append("params", params);
  126.    resp = await fetch('/ajax/deleteFile.php', {method: "POST", body: formData});
  127.    try {
  128.     var jobj = await resp.json();
  129.    }catch(e){
  130.     jobj = {};
  131.    }
  132.    
  133.    if(typeof jobj.error !== 'undefined'){
  134.     if(jobj.error==0){
  135.         console.log(jobj,objViewAjax,num);
  136.         if(typeof jobj.html !== 'undefined' && typeof objViewAjax.innerHTML !== 'undefined' ){
  137.             objViewAjax.innerHTML = jobj.html;/*hapus tampilan*/
  138.              
  139.         }
  140.         if(typeof jobj.message !== 'undefined'){
  141.             setTimeout(function (){
  142.                 alert(jobj.message);
  143.                 infoUpload=1;
  144.             }, 1000);  
  145.         }else{
  146.        
  147.         }
  148.     }else if(typeof jobj.message !== 'undefined'){  
  149.         alert(jobj.message);
  150.         infoUpload=2;
  151.     }else{
  152.         alert("undefined error");
  153.         infoUpload=3;
  154.     }
  155.                  
  156.    }else{
  157.         alert("please try again");
  158.         infoUpload=4;
  159.    }  
  160.    
  161.   })();    
  162.  }
  163.     catch(err) {
  164.       alert("undefined error");
  165.       infoDelete=3;
  166.     }
  167.     finally{
  168.         if(infoDelete==0){
  169.             alert("Delete success");
  170.         }
  171.     }
  172.  
  173. }
  174.  
  175. async function saveFile(num)  
  176. {
  177.     let formData = new FormData();
  178.     let nameObj = "fileAjax" + num;
  179.     let objAjax = document.getElementById(nameObj);
  180.     let nameViewObj = "infoFileAjax" + num;
  181.     let objViewAjax = document.getElementById(nameViewObj);
  182.     let strBefore = objViewAjax.innerHTML;
  183.     let params = objAjax.getAttributeNode("param").value;
  184.     let infoUpload=-1;
  185.     try {  
  186.         strWaiting='';//&#128336;
  187.         for(iWait=36;iWait<48;iWait++){
  188.             strWaiting+="&#1283"+iWait+";";
  189.         }
  190.         objViewAjax.innerHTML = strWaiting;
  191.         (async () => {
  192.             formData.append("file", objAjax.files[0]);
  193.             formData.append("params", params);
  194.             resp = await fetch('/ajax/uploadFile.php', {method: "POST", body: formData});
  195.            try {
  196.             console.log(resp);
  197.             var jobj = await resp.json();
  198.            }catch(e){
  199.             jobj = {};
  200.            }
  201.  
  202.             if(typeof jobj.error !== 'undefined'){
  203.                 if(jobj.error==0){
  204.                     if(typeof jobj.message !== 'undefined'){
  205.                         setTimeout(function (){
  206.                             alert("info:"+jobj.message);
  207.                             infoUpload=1;  
  208.                             if(typeof jobj.html !== 'undefined'){
  209.                                 objViewAjax.innerHTML = jobj.html;
  210.                             }
  211.                         }, 1000);  
  212.                     }else{
  213.                          
  214.                     }
  215.                 }else if(typeof jobj.message !== 'undefined'){  
  216.                     alert(jobj.message);
  217.                     infoUpload=2;
  218.                     objViewAjax.innerHTML = strBefore;
  219.                 }else{
  220.                     alert("undefined error");
  221.                     infoUpload=3;
  222.                     objViewAjax.innerHTML = strBefore;                 
  223.                 }
  224.                  
  225.             }else{
  226.                 alert("please try again");
  227.                 infoUpload=4;
  228.                 objViewAjax.innerHTML = strBefore;
  229.             }            
  230.  
  231.         })();    
  232.     }
  233.     catch(err) {
  234.       alert("undefined error");
  235.       infoUpload=3;
  236.       objViewAjax.innerHTML = strBefore;
  237.     }
  238.     finally{
  239.         if(infoUpload==0){
  240.             alert("upload success");
  241.         }
  242.     }
  243. }
  244. </script>
Tags: php ajax
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement