Jump to content

ScottMeyer

New Members
  • Posts

    6
  • Joined

  • Last visited

Community Answers

  1. ScottMeyer's post in Generate tree directory for Fancytree was marked as the answer   
    Ok I found the solution.
    It's crazy I spent the day yesterday on this problem.
    and today I finally find the solution. Thank you requinix for answering me.
    I put here my solution (not perfect) but it works.
    <?php if(session_status() != 2) { session_start(); } else { header('Location: deco.php'); } // (2 = session active) if don't active session if (!isset($_SESSION['username']) || empty($_SESSION['username'])) {header('Location: deco.php');} // redirection si pas de session ouverte if (time() > $_SESSION['expire']) { session_destroy(); header('Location: deco.php'); } $e1 = isset($_POST['e1']) ? $_POST['e1'] : null; $e2 = isset($_POST['e2']) ? $_POST['e2'] : null; if (empty($e1) || empty($e2)) { $return_data['key1'] = 'error'; echo json_encode($return_data); return; } if ($e1 == 'read'){ $e2 = str_replace('<','',$e2); // just for prevent html injection $e2 = str_replace('?','',$e2); // just for prevent php injection $return_data['key1'] = 'read'; $return_data['key2'] = $e2; echo json_encode($return_data); return; $e2 = str_replace('}','',$e2); $e2 = str_replace('"','',$e2); $e2 = explode(":", $e2); // take only name node } if ($e1 == 'tree'){ if ($_SESSION['username'] !== $e2){ // verification right name user $return_data['key1'] = 'error'; $return_data['key2'] = ' tree authentication problem'; echo json_encode($return_data); return; } echo json_encode(listFolders($e2, __DIR__ . '/datausers')); // $e2 = name user return ; } function listFolders($path_user, $dir) { $dh = scandir($dir); $name_user = $path_user; $return_data = []; if (strpos($dir, "/datausers/PERSONNAL") !== false){ // PERSONNAL found ! if ($dir === __DIR__ . '/datausers/PERSONNAL') { foreach ($dh as $item) { if ($item != '.' && $item != '..') { if ($item === $name_user){ // Take only a user if (is_dir($dir . '/' . $item)) { // it's a folder $return_data[] = array( 'title' => $item, 'folder' => true, 'expanded'=> true, 'children' => listFolders($name_user, $dir . '/' . $item, $key) ); } else { // it's a file $return_data[] = [ 'title' => $item, ]; } } } } } if (strpos($dir, "/datausers/PERSONNAL/" . $name_user) !== false){ // Peter found foreach ($dh as $item) { if ($item != '.' && $item != '..') { if (is_dir($dir . '/' . $item)) { // it's a folder $return_data[] = array( 'title' => $item, 'folder' => true, 'expanded'=> true, 'children' => listFolders($name_user, $dir . '/' . $item, $key) ); } else { // it's a file $return_data[] = [ 'title' => $item, ]; } } } } } else { foreach ($dh as $item) { if ($item != '.' && $item != '..') { if (is_dir($dir . '/' . $item)) { // it's a folder $return_data[] = array( 'title' => $item, 'folder' => true, 'expanded'=> true, 'children' => listFolders($name_user, $dir . '/' . $item, $key) ); } else { // it's a file $return_data[] = [ 'title' => $item, ]; } } } } return $return_data; } ?>  
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.