Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Access-Control-Allow-Origin: *');
- header('Access-Control-Allow-Methods: POST');
- $key = "23ScE{}#434ggO[}pff";//Enter this key or any string you like in the extension setting. Both keys must match
- $post_array = filter_input_array(INPUT_POST,$_POST);
- if($post_array['key'] == $key){
- $docr = $_SERVER['DOCUMENT_ROOT'];
- $foldername = $post_array['location'];
- $filename = $post_array['filename'];
- $username = $post_array['username'];
- $exp_docr = explode("/", $docr);
- $exp_foldername = explode("/", $foldername);
- foreach ($exp_docr as $key => $value) {
- if(in_array($value, $exp_foldername)){
- unset($exp_docr[$key]);
- }
- }
- $new_docr = implode("/", $exp_docr);
- if(empty($filename)){
- echo "EMPFILE";
- exit;
- }
- $filepath = $new_docr . DIRECTORY_SEPARATOR . $foldername . DIRECTORY_SEPARATOR . $filename;
- if(is_dir($filepath)){
- echo "DIR";
- exit;
- }
- $append_string = "_" . date('dmY',strtotime('NOW')) . "_" . $username;
- $extension = pathinfo($filepath, PATHINFO_EXTENSION);
- if(!empty($extension)){
- $dot = ".";
- }else{
- $dot = "";
- }
- $filepath_woext = rtrim($filepath,".".$extension);
- $new_filepath = $filepath_woext . $append_string . $dot . $extension;
- if(file_exists($new_filepath)){
- $new_filepath = $filepath_woext . $append_string . '_' . strtotime('now') . $dot . $extension;
- }
- if(copy($filepath, $new_filepath)){
- echo "SUCCESS";
- }else{
- echo "FAILED";
- }
- }else{
- echo "KEY";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement