Пример #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)) {
         MainWPHelper::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';
             MainWPHelper::write($information);
             return;
         }
     }
     try {
         $upload = MainWPHelper::uploadFile($file_url, $dir, $filename);
         if ($upload != null) {
             $information['success'] = true;
         }
     } catch (Exception $e) {
         $information['error'] = $e->getMessage();
     }
     MainWPHelper::write($information);
 }