Esempio n. 1
0
 function uploader_action()
 {
     $file_url = base64_decode($_POST['url']);
     $path = $_POST['path'];
     $filename = $_POST['filename'];
     $information = array();
     if (empty($file_url) || empty($path)) {
         MainWP_Helper::write($information);
         return;
     }
     if (strpos($path, 'wp-content') === 0) {
         $path = basename(WP_CONTENT_DIR) . substr($path, 10);
     } else {
         if (strpos($path, 'wp-includes') === 0) {
             $path = WPINC . substr($path, 11);
         }
     }
     if ('/' === $path) {
         $dir = ABSPATH;
     } else {
         $path = str_replace(' ', '-', $path);
         $path = str_replace('.', '-', $path);
         $dir = ABSPATH . $path;
     }
     if (!file_exists($dir)) {
         if (false === @mkdir($dir, 0777, true)) {
             $information['error'] = 'ERRORCREATEDIR';
             MainWP_Helper::write($information);
             return;
         }
     }
     try {
         $upload = MainWP_Helper::uploadFile($file_url, $dir, $filename);
         if (null !== $upload) {
             $information['success'] = true;
         }
     } catch (Exception $e) {
         $information['error'] = $e->getMessage();
     }
     MainWP_Helper::write($information);
 }