Hybride Posted May 5, 2012 Share Posted May 5, 2012 Hi everyone, I have a file filled with categories (about 100K or so lines), each one by indentation (for illustration purposes, I added + instead). Quote Root + Category ++ File 1 +++ Sub Cat ++++ File 4 ++++ File 5 ++ File 2 + Category 2 ++ SubCategory 1 +++ File 1 ++ SubCategory 2 What am trying to is upload this file, and have it input into my table so jsTree can render it correctly. It correctly inserts most of the lines, but starts to get confused when reverting back to previous lines (in the above example, it will insert up to file 5 correctly, then get lost on the left/right on File 2.) Am using jsTree's create_node, but not sure why the render is failing? My (rather brute-force) upload script is below: $dataFile = fopen($file_dir . basename($_FILES['uploaded']['name']), "rb"); while (!feof($dataFile)) { $lines = array(); while (($line = fgets($dataFile)) !== false) { array_push($lines, rtrim($line)); } $count = count($lines); $res = preg_replace('/\t/i', "|", $lines); $final = preg_replace("/\s(\W)[^\w]/i", "|", $res); $i = 0; foreach($final as $string) { //$parent_id = $delimiter_count - 1; $delimiter_count = substr_count($string, '|'); //level $left = $i + 1; $right = $left + 1; preg_match("/(\|+)(\w.+)/i", $string, $match); if(isset($match[2])) { /* even this doesn't work, if I directly inject it into the tree $insert = $keysdb->query("INSERT INTO tree (`parent_id`, `position`, `left`, `right`, `level`, `title`, `type`, `post_syn_epon`, `post_author_id`) VALUES('$delimiter_count',0,'$left','$right','$delimiter_count','$match[2]','default','$match[2], ','user_id')"); */ $jstree->create_node(array( "id" => "$delimiter_count", "position" => 0, "title" => "$match[2]", "type" => "default" )); if(!$insert) { print "Failed!" . $keysdb->error; } } $i++; } } // all done close the file fclose($dataFile); Link to comment https://forums.phpfreaks.com/topic/262105-upload-tree-from-file-jstree/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.