Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2.  
  3. header('Access-Control-Allow-Origin: *');
  4. header('Access-Control-Allow-Methods: POST');
  5.  
  6. $key = "23ScE{}#434ggO[}pff";//Enter this key or any string you like in the extension setting. Both keys must match
  7.  
  8. $post_array = filter_input_array(INPUT_POST,$_POST);
  9.  
  10. if($post_array['key'] == $key){
  11.  
  12. $docr = $_SERVER['DOCUMENT_ROOT'];
  13. $foldername = $post_array['location'];
  14. $filename = $post_array['filename'];
  15. $username = $post_array['username'];
  16.  
  17. $exp_docr = explode("/", $docr);
  18. $exp_foldername = explode("/", $foldername);
  19.  
  20. foreach ($exp_docr as $key => $value) {
  21. if(in_array($value, $exp_foldername)){
  22. unset($exp_docr[$key]);
  23. }
  24. }
  25.  
  26. $new_docr = implode("/", $exp_docr);
  27.  
  28. if(empty($filename)){
  29. echo "EMPFILE";
  30. exit;
  31. }
  32.  
  33. $filepath = $new_docr . DIRECTORY_SEPARATOR . $foldername . DIRECTORY_SEPARATOR . $filename;
  34.  
  35. if(is_dir($filepath)){
  36. echo "DIR";
  37. exit;
  38. }
  39.  
  40. $append_string = "_" . date('dmY',strtotime('NOW')) . "_" . $username;
  41.  
  42. $extension = pathinfo($filepath, PATHINFO_EXTENSION);
  43.  
  44. if(!empty($extension)){
  45. $dot = ".";
  46. }else{
  47. $dot = "";
  48. }
  49.  
  50. $filepath_woext = rtrim($filepath,".".$extension);
  51.  
  52. $new_filepath = $filepath_woext . $append_string . $dot . $extension;
  53.  
  54. if(file_exists($new_filepath)){
  55.  
  56. $new_filepath = $filepath_woext . $append_string . '_' . strtotime('now') . $dot . $extension;
  57.  
  58. }
  59.  
  60. if(copy($filepath, $new_filepath)){
  61. echo "SUCCESS";
  62. }else{
  63. echo "FAILED";
  64. }
  65. }else{
  66. echo "KEY";
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement