neven Posted September 2, 2011 Share Posted September 2, 2011 [/b]Hi people I'm having problem with inplementing a check box delete form in the jquery directory tree ....Realy I need help with this ! I am using the php code below.... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <!-- CSS For The Menu --> <link rel="stylesheet" href="stylee.css" /> </head> <body> <!-- Menu Start --> <div id="jQ-menu"> <?php error_reporting(0); $path = "store/".$diro."/"; function createDir($path = '.') { if ($handle = opendir($path)) { echo "<ul>"; while (false !== ($file = readdir($handle))) { if (is_dir($path.$file) && $file != '.' && $file !='..') printSubDir($file, $path, $queue); else if ($file != '.' && $file !='..') $queue[] = $file; } printQueue($queue, $path); echo "</ul>"; } } function printQueue($queue, $path) { foreach ($queue as $file) { printFile($file, $path); } } echo"<form action='osnovni_dokumenti.php?id=" . $data['ideo']. "' method='POST'>"; function printFile($file, $path) { echo "<li><input type='checkbox' name='del[]' value='$file'/><a href=\"".$path.$file."\"><img src='slike_izgled/file.png'> $file</a></li>"; } function printSubDir($dir, $path) { echo "<li><img src='slike_izgled/directory.png' width='20' height='20'> <span class=\"toggle\">$dir</span>"; createDir($path.$dir."/"); echo "</li>"; } createDir($path); echo"<p align='center'><input type='submit' name='filedel' value='Delete'></p> </form>"; ?> </div> <!-- End Menu --> <!-- Add jQuery From the Google AJAX Libraries --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <!-- jQuery Color Plugin --> <script type="text/javascript" src="jquery.color.js"></script> <!-- Import The jQuery Script --> <script type="text/javascript" src="jMenu.js"></script> </body> </html> if(isset($_POST['filedel'])) { $id = $_POST[del]; $count = count($id); for ($i=0; $i<$count; $i++){ $files = $_POST['del']; echo"$files.$count"; } } Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/ Share on other sites More sharing options...
AyKay47 Posted September 2, 2011 Share Posted September 2, 2011 1. your jquery library should be referenced in the head of the page.. 2. what errors are you receiving..? Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264784 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 Jes I know the jquery tree is working fine but i do't know how to make the checkbox delete the file that i check ..that is the problem !!! I can't get the name from the check box i get this "array.1 that is what I put to the echo statemant... to see would I get the name of the checked file ... Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264786 Share on other sites More sharing options...
jamesxg1 Posted September 2, 2011 Share Posted September 2, 2011 Please re-post using code tags! James. Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264843 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 [list] [*][/list]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <!-- CSS For The Menu --> <link rel="stylesheet" href="stylee.css" /> </head> <body> <!-- Menu Start --> <div id="jQ-menu"> <?php error_reporting(0); $path = "store/".$diro."/"; function createDir($path = '.') { if ($handle = opendir($path)) { echo "<ul>"; while (false !== ($file = readdir($handle))) { if (is_dir($path.$file) && $file != '.' && $file !='..') printSubDir($file, $path, $queue); else if ($file != '.' && $file !='..') $queue[] = $file; } printQueue($queue, $path); echo "</ul>"; } } function printQueue($queue, $path) { foreach ($queue as $file) { printFile($file, $path); } } echo"<form action='osnovni_dokumenti.php?id=" . $data['ideo']. "' method='POST'>"; function printFile($file, $path) { echo "<li><input type='checkbox' name='del[]' value='$file'/><a href=\"".$path.$file."\"><img src='slike_izgled/file.png'> $file</a></li>"; } function printSubDir($dir, $path) { echo "<li><img src='slike_izgled/directory.png' width='20' height='20'> <span class=\"toggle\">$dir</span>"; createDir($path.$dir."/"); echo "</li>"; } createDir($path); echo"<p align='center'><input type='submit' name='filedel' value='Delete'></p> </form>"; ?> </div> <!-- End Menu --> <!-- Add jQuery From the Google AJAX Libraries --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <!-- jQuery Color Plugin --> <script type="text/javascript" src="jquery.color.js"></script> <!-- Import The jQuery Script --> <script type="text/javascript" src="jMenu.js"></script> </body> </html> <?php if(isset($_POST['filedel'])) { $id = $_POST[del]; $count = count($id); for ($i=0; $i<$count; $i++){ $files = $_POST['del']; echo"$files.$count"; echo '<pre>' . print_r($file, true) . '</pre>'; echo '<pre>' . print_r($files, true) . '</pre>'; echo $file[0] . ' - ' . $file[1] . '<br />'; echo $files[0] . ' - ' . $files[1] . '<br />'; } } ?> [list] [*] [/list] Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264845 Share on other sites More sharing options...
jamesxg1 Posted September 2, 2011 Share Posted September 2, 2011 I'm not fully sure I understand what it is that's going wrong for you, but I've cleaned up your code and changed a few things, so give this a try. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <!-- CSS For The Menu --> <link rel="stylesheet" href="stylee.css" /> <!-- Add jQuery From the Google AJAX Libraries --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <!-- jQuery Color Plugin --> <script type="text/javascript" src="jquery.color.js"></script> <!-- Import The jQuery Script --> <script type="text/javascript" src="jMenu.js"></script> </head> <body> <!-- Menu Start --> <div id="jQ-menu"> <?php error_reporting(0); $path = "store/" . $diro . "/"; function createDir($path = '.') { $handle = opendir($path); if($handle) { echo "<ul>"; while(false !== ($file = readdir($handle))) { if(is_dir($path . $file) && $file !== '.' && $file !== '..') { printSubDir($file, $path, $queue); } elseif($file !== '.' && $file !== '..') { $queue[] = $file; } } printQueue($queue, $path); echo "</ul>"; } } function printQueue($queue, $path) { foreach($queue as $file) { foreach($file as $FK => $FV) { printFile($FV, $path); } } } echo"<form action='osnovni_dokumenti.php?id=" . $data['ideo'] . "' method='POST'>"; function printFile($file, $path) { echo "<li><input type='checkbox' name='del[]' value='$file'/><a href=\"" . $path . $file . "\"><img src='slike_izgled/file.png'> $file</a></li>"; } function printSubDir($dir, $path) { echo "<li><img src='slike_izgled/directory.png' width='20' height='20'> <span class=\"toggle\">$dir</span>"; createDir($path . $dir . "/"); echo "</li>"; } createDir($path); echo"<p align='center'><input type='submit' name='filedel' value='Delete'></p> </form>"; ?> </div> <!-- End Menu --> </body> </html> <?php if(isset($_POST['filedel'])) { $id = $_POST['del']; $count = count($id); for($i = 0; $i < $count; $i++) { $files = $_POST['del']; echo"$files.$count"; echo '<pre>' . print_r($file, true) . '</pre>'; echo '<pre>' . print_r($files, true) . '</pre>'; echo $file[0] . ' - ' . $file[1] . '<br />'; echo $files[0] . ' - ' . $files[1] . '<br />'; } } ?> James. Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264864 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 I'm not fully sure I understand what it is that's going wrong for you, but I've cleaned up your code and changed a few things, so give this a try. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <!-- CSS For The Menu --> <link rel="stylesheet" href="stylee.css" /> <!-- Add jQuery From the Google AJAX Libraries --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <!-- jQuery Color Plugin --> <script type="text/javascript" src="jquery.color.js"></script> <!-- Import The jQuery Script --> <script type="text/javascript" src="jMenu.js"></script> </head> <body> <!-- Menu Start --> <div id="jQ-menu"> <?php error_reporting(0); $path = "store/" . $diro . "/"; function createDir($path = '.') { $handle = opendir($path); if($handle) { echo "<ul>"; while(false !== ($file = readdir($handle))) { if(is_dir($path . $file) && $file !== '.' && $file !== '..') { printSubDir($file, $path, $queue); } elseif($file !== '.' && $file !== '..') { $queue[] = $file; } } printQueue($queue, $path); echo "</ul>"; } } function printQueue($queue, $path) { foreach($queue as $file) { foreach($file as $FK => $FV) { printFile($FV, $path); } } } echo"<form action='osnovni_dokumenti.php?id=" . $data['ideo'] . "' method='POST'>"; function printFile($file, $path) { echo "<li><input type='checkbox' name='del[]' value='$file'/><a href=\"" . $path . $file . "\"><img src='slike_izgled/file.png'> $file</a></li>"; } function printSubDir($dir, $path) { echo "<li><img src='slike_izgled/directory.png' width='20' height='20'> <span class=\"toggle\">$dir</span>"; createDir($path . $dir . "/"); echo "</li>"; } createDir($path); echo"<p align='center'><input type='submit' name='filedel' value='Delete'></p> </form>"; ?> </div> <!-- End Menu --> </body> </html> <?php if(isset($_POST['filedel'])) { $id = $_POST['del']; $count = count($id); for($i = 0; $i < $count; $i++) { $files = $_POST['del']; echo"$files.$count"; echo '<pre>' . print_r($file, true) . '</pre>'; echo '<pre>' . print_r($files, true) . '</pre>'; echo $file[0] . ' - ' . $file[1] . '<br />'; echo $files[0] . ' - ' . $files[1] . '<br />'; } } ?> James. OK I'l try to explain to you sou I'v got directory tree and files in that directory's, by every file I have check box and on the end submit buton . What I need is function that whill delete the file, " in this case the file is the $file variable", that I have mark in check box.Now when I click the submit button I get -> example down... Array ( [0] => Dundo Maroje.txt ) - Dundo Maroje.txt - Now this file "Dundo Maroje.txt" must bee deleted from the directory ... How to doo that ? ONLY THE CHECKED FILE MUST BEE DELETED WHEN i SUBMIT THE FORM ... understand? Sory my english is litle por... Soo can you help ? Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264871 Share on other sites More sharing options...
jamesxg1 Posted September 2, 2011 Share Posted September 2, 2011 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <!-- CSS For The Menu --> <link rel="stylesheet" href="stylee.css" /> <!-- Add jQuery From the Google AJAX Libraries --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <!-- jQuery Color Plugin --> <script type="text/javascript" src="jquery.color.js"></script> <!-- Import The jQuery Script --> <script type="text/javascript" src="jMenu.js"></script> </head> <body> <!-- Menu Start --> <div id="jQ-menu"> <?php error_reporting(0); $path = "store/" . $diro . "/"; function createDir($path = '.') { $handle = opendir($path); if($handle) { echo "<ul>"; while(false !== ($file = readdir($handle))) { if(is_dir($path . $file) && $file !== '.' && $file !== '..') { printSubDir($file, $path, $queue); } elseif($file !== '.' && $file !== '..') { $queue[] = $file; } } printQueue($queue, $path); echo "</ul>"; } } function printQueue($queue, $path) { foreach($queue as $file) { foreach($file as $FK => $FV) { printFile($FV, $path); } } } echo"<form action='osnovni_dokumenti.php?id=" . $data['ideo'] . "' method='POST'>"; function printFile($file, $path) { echo "<li><input type='checkbox' name='del[]' value='$file'/><a href=\"" . $path . $file . "\"><img src='slike_izgled/file.png'> $file</a></li>"; } function printSubDir($dir, $path) { echo "<li><img src='slike_izgled/directory.png' width='20' height='20'> <span class=\"toggle\">$dir</span>"; createDir($path . $dir . "/"); echo "</li>"; } createDir($path); echo"<p align='center'><input type='submit' name='filedel' value='Delete'></p> </form>"; ?> </div> <!-- End Menu --> </body> </html> <?php if(isset($_POST['filedel'])) { $id = $_POST['del']; $count = count($id); for($i = 0; $i < $count; $i++) { $files = $_POST['del']; echo"$files.$count"; echo '<pre>' . print_r($file, true) . '</pre>'; echo '<pre>' . print_r($files, true) . '</pre>'; echo $file[0] . ' - ' . $file[1] . '<br />'; echo $files[0] . ' - ' . $files[1] . '<br />'; if(unlink('store' . $file[$i])) { echo 'File ' . $file[$i] . ' deleted.'; } else { echo 'Failed to delete ' . $file[$i]; } } } ?> Try that. James. Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264874 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <!-- CSS For The Menu --> <link rel="stylesheet" href="stylee.css" /> <!-- Add jQuery From the Google AJAX Libraries --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <!-- jQuery Color Plugin --> <script type="text/javascript" src="jquery.color.js"></script> <!-- Import The jQuery Script --> <script type="text/javascript" src="jMenu.js"></script> </head> <body> <!-- Menu Start --> <div id="jQ-menu"> <?php error_reporting(0); $path = "store/" . $diro . "/"; function createDir($path = '.') { $handle = opendir($path); if($handle) { echo "<ul>"; while(false !== ($file = readdir($handle))) { if(is_dir($path . $file) && $file !== '.' && $file !== '..') { printSubDir($file, $path, $queue); } elseif($file !== '.' && $file !== '..') { $queue[] = $file; } } printQueue($queue, $path); echo "</ul>"; } } function printQueue($queue, $path) { foreach($queue as $file) { foreach($file as $FK => $FV) { printFile($FV, $path); } } } echo"<form action='osnovni_dokumenti.php?id=" . $data['ideo'] . "' method='POST'>"; function printFile($file, $path) { echo "<li><input type='checkbox' name='del[]' value='$file'/><a href=\"" . $path . $file . "\"><img src='slike_izgled/file.png'> $file</a></li>"; } function printSubDir($dir, $path) { echo "<li><img src='slike_izgled/directory.png' width='20' height='20'> <span class=\"toggle\">$dir</span>"; createDir($path . $dir . "/"); echo "</li>"; } createDir($path); echo"<p align='center'><input type='submit' name='filedel' value='Delete'></p> </form>"; ?> </div> <!-- End Menu --> </body> </html> <?php if(isset($_POST['filedel'])) { $id = $_POST['del']; $count = count($id); for($i = 0; $i < $count; $i++) { $files = $_POST['del']; echo"$files.$count"; echo '<pre>' . print_r($file, true) . '</pre>'; echo '<pre>' . print_r($files, true) . '</pre>'; echo $file[0] . ' - ' . $file[1] . '<br />'; echo $files[0] . ' - ' . $files[1] . '<br />'; if(unlink('store' . $file[$i])) { echo 'File ' . $file[$i] . ' deleted.'; } else { echo 'Failed to delete ' . $file[$i]; } } } ?> Try that. James. I hav tried but it get back this : Array ( [0] => popis.txt ) - popis.txt - Failed to delete Ther is no " $file[$i];" in the Faild to delete so ther is no varible in the unlink ? or???? Why? Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264878 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 Please if you can help mee :'( ? Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264886 Share on other sites More sharing options...
jamesxg1 Posted September 2, 2011 Share Posted September 2, 2011 Neven, the code you have is very poorly composed. I have written this for you to get you back on track but you cannot expect people to write thee entire script for you because your code is messy. Anyway, I hope this helps. <?php /** * @author James Pollard */ class createTree { private $FilePath; private $TreeData; public function __construct() { $this->FilePath = 'YOUR DIRECTORY HERE! DO NOT PUT A SLASH AT THE END OF IT!'; $this->GenerateTreeData(); return true; } public function deleteFile($FileID) { if(is_file($FileID)) { if(unlink($FileID)) { return 'File ' . $FileID . ' has been deleted.'; } else { return 'Failed to delete file ' . $FileID . '.'; } } else { return 'File ' . $FileID . ' does not exist.'; } } private function GenerateTreeData() { $ParentFolder = scandir($this->FilePath . '/'); $this->TreeData = array(); $Folders = array(); foreach($ParentFolder as $PFK => $PFV) { if($PFV !== '.' && $PFV !== '..') { if(is_file($this->FilePath . '/' . $PFV)) { $this->TreeData[$this->FilePath] = $PFV; } elseif(is_dir($this->FilePath . '/' . $PFV)) { $this->TreeData[$this->FilePath][$PFV] = array(); $Folders[] = $PFV; } } } $this->ScanFolders($Folders); return $this->TreeData; } private function ScanFolders($Folders) { foreach($Folders as $FK => $FV) { $FolderData = scandir($this->FilePath . '/' . $FV . '/'); foreach($FolderData as $FDK => $FDV) { if($FDV !== '.' && $FDV !== '..') { if(is_file($this->FilePath . '/' . $FV . '/' . $FDV)) { if(strpos($FV, '/') !== false) { $TP = explode('/', $FV); $this->TreeData[$this->FilePath][$TP[0]][$TP[1]][] = $FDV; } else { $this->TreeData[$this->FilePath][$FV][] = $FDV; } } elseif(is_dir($this->FilePath . '/' . $FV . '/' . $FDV)) { $this->TreeData[$this->FilePath][$FV][$FDV] = array(); $Folders[] = $FV . '/' . $FDV; } } } unset($Folders[$FK]); } if(count($Folders) === 0) { return true; } else { $this->ScanFolders($Folders); } } private function CreateTreeFolder($Folder, $ParentFolder) { if(is_string($Folder)) { return '<ul><li><img src="slike_izgled/directory.png" width="20" height="20"> <span class="toggle">' . $Folder . '</span>'; } elseif(is_array($Folder)) { $Return = ''; foreach($Folder as $TFK => $TFV) { if(is_array($TFV)) { $Return .= $this->CreateTreeFolder($TFK, $ParentFolder); $Return .= $this->CreateTreeFile($TFV, $ParentFolder . '/' . $TFK); $Return .= '</li></ul>'; } else { $Return .= $this->CreateTreeFile($TFV, $ParentFolder); } } return $Return; } else { return ''; } } private function CreateTreeFile($File, $Folder) { if(is_string($File)) { return '<li><input type="checkbox" name="delfile[]" value="' . $this->FilePath . '/' . $Folder . '/' . $File . '"/><a href="' . $this->FilePath . '/' . $Folder . '/' . $File . '"><img src="slike_izgled/file.png"> ' . $File . '</a></li>'; } elseif(is_array($File)) { $Return = ''; foreach($File as $TFK => $TFV) { $Return .= '<li><input type="checkbox" name="delfile[]" value="' . $this->FilePath . '/' . $Folder . '/' . $TFV . '"/><a href="' . $this->FilePath . '/' . $Folder . '/' . $TFV . '"><img src="slike_izgled/file.png"> ' . $TFV . '</a></li>'; } return $Return; } } public function CreateTree() { $Return = '<ul>'; $Return .= $this->CreateTreeFolder($this->FilePath, $this->FilePath); foreach($this->TreeData[$this->FilePath] as $TK => $TV) { if(is_array($TV)) { $Return .= '<ul><li><img src="slike_izgled/directory.png" width="20" height="20"> <span class="toggle">' . $TK . '</span>'; $Return .= $this->CreateTreeFolder($TV, $TK); $Return .= '</li></ul>'; } else { $Return .= $this->CreateTreeFile($TV, $TK); } } $Return .= '</ul>'; return $Return; } public function __destruct() { return true; } } $CT = new createTree; if(isset($_POST['filedel'])) { $Response = ''; if(isset($_POST['delfile']) && !empty($_POST['delfile']) && is_array($_POST['delfile']) && count($_POST['delfile']) > 0) { foreach($_POST['delfile'] as $DFK => $DFV) { $Response .= $CT->deleteFile($DFV) . '<br />'; } } else { $Response = 'Please select a file to delete.'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <link rel="stylesheet" href="stylee.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <script type="text/javascript" src="jquery.color.js"></script> <script type="text/javascript" src="jMenu.js"></script> </head> <body> <div id="jQ-menu"> <b><?php echo $Response; ?></b> <!--- osnovni_dokumenti.php?id=</?php echo $data['ideo']; ?> ---> <form action="#" method="post"> <?php echo $CT->CreateTree(); ?> <p align='center'> <input type="submit" name="filedel" value="Delete" /> </p> </form> </div> </body> </html> James. Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264911 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 I'm greatful for this Thank you ...usualy I'm not like that this is firs time that I'm haveing this much suffering ... Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264923 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 Neven, the code you have is very poorly composed. I have written this for you to get you back on track but you cannot expect people to write thee entire script for you because your code is messy. Anyway, I hope this helps. <?php /** * @author James Pollard */ class createTree { private $FilePath; private $TreeData; public function __construct() { $this->FilePath = 'YOUR DIRECTORY HERE! DO NOT PUT A SLASH AT THE END OF IT!'; $this->GenerateTreeData(); return true; } public function deleteFile($FileID) { if(is_file($FileID)) { if(unlink($FileID)) { return 'File ' . $FileID . ' has been deleted.'; } else { return 'Failed to delete file ' . $FileID . '.'; } } else { return 'File ' . $FileID . ' does not exist.'; } } private function GenerateTreeData() { $ParentFolder = scandir($this->FilePath . '/'); $this->TreeData = array(); $Folders = array(); foreach($ParentFolder as $PFK => $PFV) { if($PFV !== '.' && $PFV !== '..') { if(is_file($this->FilePath . '/' . $PFV)) { $this->TreeData[$this->FilePath] = $PFV; } elseif(is_dir($this->FilePath . '/' . $PFV)) { $this->TreeData[$this->FilePath][$PFV] = array(); $Folders[] = $PFV; } } } $this->ScanFolders($Folders); return $this->TreeData; } private function ScanFolders($Folders) { foreach($Folders as $FK => $FV) { $FolderData = scandir($this->FilePath . '/' . $FV . '/'); foreach($FolderData as $FDK => $FDV) { if($FDV !== '.' && $FDV !== '..') { if(is_file($this->FilePath . '/' . $FV . '/' . $FDV)) { if(strpos($FV, '/') !== false) { $TP = explode('/', $FV); $this->TreeData[$this->FilePath][$TP[0]][$TP[1]][] = $FDV; } else { $this->TreeData[$this->FilePath][$FV][] = $FDV; } } elseif(is_dir($this->FilePath . '/' . $FV . '/' . $FDV)) { $this->TreeData[$this->FilePath][$FV][$FDV] = array(); $Folders[] = $FV . '/' . $FDV; } } } unset($Folders[$FK]); } if(count($Folders) === 0) { return true; } else { $this->ScanFolders($Folders); } } private function CreateTreeFolder($Folder, $ParentFolder) { if(is_string($Folder)) { return '<ul><li><img src="slike_izgled/directory.png" width="20" height="20"> <span class="toggle">' . $Folder . '</span>'; } elseif(is_array($Folder)) { $Return = ''; foreach($Folder as $TFK => $TFV) { if(is_array($TFV)) { $Return .= $this->CreateTreeFolder($TFK, $ParentFolder); $Return .= $this->CreateTreeFile($TFV, $ParentFolder . '/' . $TFK); $Return .= '</li></ul>'; } else { $Return .= $this->CreateTreeFile($TFV, $ParentFolder); } } return $Return; } else { return ''; } } private function CreateTreeFile($File, $Folder) { if(is_string($File)) { return '<li><input type="checkbox" name="delfile[]" value="' . $this->FilePath . '/' . $Folder . '/' . $File . '"/><a href="' . $this->FilePath . '/' . $Folder . '/' . $File . '"><img src="slike_izgled/file.png"> ' . $File . '</a></li>'; } elseif(is_array($File)) { $Return = ''; foreach($File as $TFK => $TFV) { $Return .= '<li><input type="checkbox" name="delfile[]" value="' . $this->FilePath . '/' . $Folder . '/' . $TFV . '"/><a href="' . $this->FilePath . '/' . $Folder . '/' . $TFV . '"><img src="slike_izgled/file.png"> ' . $TFV . '</a></li>'; } return $Return; } } public function CreateTree() { $Return = '<ul>'; $Return .= $this->CreateTreeFolder($this->FilePath, $this->FilePath); foreach($this->TreeData[$this->FilePath] as $TK => $TV) { if(is_array($TV)) { $Return .= '<ul><li><img src="slike_izgled/directory.png" width="20" height="20"> <span class="toggle">' . $TK . '</span>'; $Return .= $this->CreateTreeFolder($TV, $TK); $Return .= '</li></ul>'; } else { $Return .= $this->CreateTreeFile($TV, $TK); } } $Return .= '</ul>'; return $Return; } public function __destruct() { return true; } } $CT = new createTree; if(isset($_POST['filedel'])) { $Response = ''; if(isset($_POST['delfile']) && !empty($_POST['delfile']) && is_array($_POST['delfile']) && count($_POST['delfile']) > 0) { foreach($_POST['delfile'] as $DFK => $DFV) { $Response .= $CT->deleteFile($DFV) . '<br />'; } } else { $Response = 'Please select a file to delete.'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <link rel="stylesheet" href="stylee.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <script type="text/javascript" src="jquery.color.js"></script> <script type="text/javascript" src="jMenu.js"></script> </head> <body> <div id="jQ-menu"> <b><?php echo $Response; ?></b> <!--- osnovni_dokumenti.php?id=</?php echo $data['ideo']; ?> ---> <form action="#" method="post"> <?php echo $CT->CreateTree(); ?> <p align='center'> <input type="submit" name="filedel" value="Delete" /> </p> </form> </div> </body> </html> James. But ther is a litl problem vith the construction of the directory tree ....It must look like this ->The first atachment and the second is how it loks like now... Can you do this for me ? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264928 Share on other sites More sharing options...
jamesxg1 Posted September 2, 2011 Share Posted September 2, 2011 My pleasure, anytime :-)! Hope it helps Neven. Replace <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> With <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> Happy coding! James. P.S; Remember to make this topic as SOLVED :-). Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264932 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 My pleasure, anytime :-)! Hope it helps Neven. Replace <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> With <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> Happy coding! James. P.S; Remember to make this topic as SOLVED :-). No i MENT the directory tree is not opening the files and dir like my firs one .... Understand ? Maybe not .... in the directorys I need that from one directory come out the other three directory's 3 like on the picture ... like this frst dir is the FIRST DIR IS-"ID" FROM THAT directory it comes out the other tree like on the picture -> osnovni dokumenti, ostali dokumenti, & pictures U know what I meen ? Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264939 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 How can I change the hierarhy of the directory tree? That is the problem Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264941 Share on other sites More sharing options...
neven Posted September 2, 2011 Author Share Posted September 2, 2011 Now it opens all the directorys from the file path example "store" but I need the tree that opens specified directorys named by the variable... Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264948 Share on other sites More sharing options...
neven Posted September 3, 2011 Author Share Posted September 3, 2011 Look all I have in this php code is corect AND I need it yust like that .........The onnly thing I NEED IS THE DELETE FUNCION IN THIS SCRIPT .... The script that you make is ok but it is not the sam structure..... sou this is the code that I vont to use ....Sou directory tree must have the same hierarhy as it is in this script below .....ALL I NEED IS THE CHECK BOX UNLINK FUNKCION ...THAT CAN DELETE FILES IN DIRECTORY'S And all files must bee in the directory's ....Sou James if you woul bee so kind Or whou ever have the answer ,...please help this is first time that i have come up on that hard ploblem .... THANKS FORWARD if(isset($_POST['pregled'])) { //start of list $id = $_GET['id']; $q = "SELECT * FROM albums WHERE $id = ideo"; $results = mysql_query($q); $data = mysql_fetch_array($results); $diro = $data['dosjeid']; $id = $data['ideo']; //open the dir echo"<table border='2' cellpadding='5' width='630'> <tr> <td width='300'>"; ?> <!--start of dir tree!--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <!-- CSS For The Menu --> <link rel="stylesheet" href="stylee.css" /> </head> <body> <!-- Menu Start --> <div id="jQ-menu"> <?php error_reporting(0); $path = "store/".$diro; ///////////I need this variable !!! function createDir($path = '.') { if ($handle = opendir($path)) { echo "<ul>"; while (false !== ($file = readdir($handle))) { if (is_dir($path.$file) && $file != '.' && $file !='..') printSubDir($file, $path, $queue); else if ($file != '.' && $file !='..') $queue[] = $file; } printQueue($queue, $path); echo "</ul>"; } } function printQueue($queue, $path) { foreach ($queue as $file) { printFile($file, $path); } } echo"<form action='osnovni_dokumenti.php?id=" . $data['ideo']. "' method='POST'>"; function printFile($file, $path) { echo "<li><input type='checkbox' name='del[]' value='$file'/><a href=\"".$path.$file."\"><img src='slike_izgled/file.png'> $file</a></li>"; } function printSubDir($dir, $path) { echo "<li><img src='slike_izgled/directory.png' width='20' height='20'> <span class=\"toggle\">$dir</span>"; createDir($path.$dir."/"); echo "</li>"; } createDir($path); echo"<p align='center'><input type='submit' name='filedel' value='Delete'></p> </form>"; ?> </div> <!-- End Menu --> <!-- Add jQuery From the Google AJAX Libraries --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <!-- jQuery Color Plugin --> <script type="text/javascript" src="jquery.color.js"></script> <!-- Import The jQuery Script --> <script type="text/javascript" src="jMenu.js"></script> </body> </html> <!--end of tree!--> <? //Now this is wher the submit button need to delete the file... if(isset($_POST['filedel'])) { /////////////////////////////////////////////////Missing code!!!!!!!!!!!!!!!!!!!!!!!! } The picture below shows how it should look like.... [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1264976 Share on other sites More sharing options...
jamesxg1 Posted September 3, 2011 Share Posted September 3, 2011 <?php /** * @author James Pollard */ if(isset($_POST['pregled'])) { $id = $_GET['id']; $q = "SELECT * FROM `albums` WHERE `" . $id . "` = 'ideo'"; $results = mysql_query($q); $data = mysql_fetch_array($results); $diro = $data['dosjeid']; $id = $data['ideo']; class createTree { private $FilePath; private $TreeData; public function __construct($DirInput) { $this->FilePath = $DirInput; $this->GenerateTreeData(); return true; } public function deleteFile($FileID) { if(is_file($FileID)) { if(unlink($FileID)) { return 'File ' . $FileID . ' has been deleted.'; } else { return 'Failed to delete file ' . $FileID . '.'; } } else { return 'File ' . $FileID . ' does not exist.'; } } private function GenerateTreeData() { $ParentFolder = scandir($this->FilePath . '/'); $this->TreeData = array(); $Folders = array(); foreach($ParentFolder as $PFK => $PFV) { if($PFV !== '.' && $PFV !== '..') { if(is_file($this->FilePath . '/' . $PFV)) { $this->TreeData[$this->FilePath] = $PFV; } elseif(is_dir($this->FilePath . '/' . $PFV)) { $this->TreeData[$this->FilePath][$PFV] = array(); $Folders[] = $PFV; } } } $this->ScanFolders($Folders); return $this->TreeData; } private function ScanFolders($Folders) { foreach($Folders as $FK => $FV) { $FolderData = scandir($this->FilePath . '/' . $FV . '/'); foreach($FolderData as $FDK => $FDV) { if($FDV !== '.' && $FDV !== '..') { if(is_file($this->FilePath . '/' . $FV . '/' . $FDV)) { if(strpos($FV, '/') !== false) { $TP = explode('/', $FV); $this->TreeData[$this->FilePath][$TP[0]][$TP[1]][] = $FDV; } else { $this->TreeData[$this->FilePath][$FV][] = $FDV; } } elseif(is_dir($this->FilePath . '/' . $FV . '/' . $FDV)) { $this->TreeData[$this->FilePath][$FV][$FDV] = array(); $Folders[] = $FV . '/' . $FDV; } } } unset($Folders[$FK]); } if(count($Folders) === 0) { return true; } else { $this->ScanFolders($Folders); } } private function CreateTreeFolder($Folder, $ParentFolder) { if(is_string($Folder)) { return '<ul><li><img src="slike_izgled/directory.png" width="20" height="20"> <span class="toggle">' . $Folder . '</span>'; } elseif(is_array($Folder)) { $Return = ''; foreach($Folder as $TFK => $TFV) { if(is_array($TFV)) { $Return .= $this->CreateTreeFolder($TFK, $ParentFolder); $Return .= $this->CreateTreeFile($TFV, $ParentFolder . '/' . $TFK); $Return .= '</li></ul>'; } else { $Return .= $this->CreateTreeFile($TFV, $ParentFolder); } } return $Return; } else { return ''; } } private function CreateTreeFile($File, $Folder) { if(is_string($File)) { return '<li><input type="checkbox" name="delfile[]" value="' . $this->FilePath . '/' . $Folder . '/' . $File . '"/><a href="' . $this->FilePath . '/' . $Folder . '/' . $File . '"><img src="slike_izgled/file.png"> ' . $File . '</a></li>'; } elseif(is_array($File)) { $Return = ''; foreach($File as $TFK => $TFV) { $Return .= '<li><input type="checkbox" name="delfile[]" value="' . $this->FilePath . '/' . $Folder . '/' . $TFV . '"/><a href="' . $this->FilePath . '/' . $Folder . '/' . $TFV . '"><img src="slike_izgled/file.png"> ' . $TFV . '</a></li>'; } return $Return; } } public function CreateTree() { $Return = '<ul>'; $Return .= $this->CreateTreeFolder($this->FilePath, $this->FilePath); foreach($this->TreeData[$this->FilePath] as $TK => $TV) { if(is_array($TV)) { $Return .= '<ul><li><img src="slike_izgled/directory.png" width="20" height="20"> <span class="toggle">' . $TK . '</span>'; $Return .= $this->CreateTreeFolder($TV, $TK); $Return .= '</li></ul>'; } else { $Return .= $this->CreateTreeFile($TV, $TK); } } $Return .= '</ul>'; return $Return; } public function __destruct() { return true; } } $CT = new createTree($diro); if(isset($_POST['filedel'])) { $Response = ''; if(isset($_POST['delfile']) && !empty($_POST['delfile']) && is_array($_POST['delfile']) && count($_POST['delfile']) > 0) { foreach($_POST['delfile'] as $DFK => $DFV) { $Response .= $CT->deleteFile($DFV) . '<br />'; } } else { $Response = 'Please select a file to delete.'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <link rel="stylesheet" href="stylee.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <script type="text/javascript" src="jquery.color.js"></script> <script type="text/javascript" src="jMenu.js"></script> </head> <body> <div id="jQ-menu"> <b><?php echo $Response; ?></b> <!--- osnovni_dokumenti.php?id=</?php echo $data['ideo']; ?> ---> <form action="#" method="post"> <?php echo $CT->CreateTree(); ?> <p align='center'> <input type="submit" name="filedel" value="Delete" /> </p> </form> </div> </body> </html> <?php } ?> James. Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1265054 Share on other sites More sharing options...
neven Posted September 3, 2011 Author Share Posted September 3, 2011 <?php /** * @author James Pollard */ if(isset($_POST['pregled'])) { $id = $_GET['id']; $q = "SELECT * FROM `albums` WHERE `" . $id . "` = 'ideo'"; $results = mysql_query($q); $data = mysql_fetch_array($results); $diro = $data['dosjeid']; $id = $data['ideo']; class createTree { private $FilePath; private $TreeData; public function __construct($DirInput) { $this->FilePath = $DirInput; $this->GenerateTreeData(); return true; } public function deleteFile($FileID) { if(is_file($FileID)) { if(unlink($FileID)) { return 'File ' . $FileID . ' has been deleted.'; } else { return 'Failed to delete file ' . $FileID . '.'; } } else { return 'File ' . $FileID . ' does not exist.'; } } private function GenerateTreeData() { $ParentFolder = scandir($this->FilePath . '/'); $this->TreeData = array(); $Folders = array(); foreach($ParentFolder as $PFK => $PFV) { if($PFV !== '.' && $PFV !== '..') { if(is_file($this->FilePath . '/' . $PFV)) { $this->TreeData[$this->FilePath] = $PFV; } elseif(is_dir($this->FilePath . '/' . $PFV)) { $this->TreeData[$this->FilePath][$PFV] = array(); $Folders[] = $PFV; } } } $this->ScanFolders($Folders); return $this->TreeData; } private function ScanFolders($Folders) { foreach($Folders as $FK => $FV) { $FolderData = scandir($this->FilePath . '/' . $FV . '/'); foreach($FolderData as $FDK => $FDV) { if($FDV !== '.' && $FDV !== '..') { if(is_file($this->FilePath . '/' . $FV . '/' . $FDV)) { if(strpos($FV, '/') !== false) { $TP = explode('/', $FV); $this->TreeData[$this->FilePath][$TP[0]][$TP[1]][] = $FDV; } else { $this->TreeData[$this->FilePath][$FV][] = $FDV; } } elseif(is_dir($this->FilePath . '/' . $FV . '/' . $FDV)) { $this->TreeData[$this->FilePath][$FV][$FDV] = array(); $Folders[] = $FV . '/' . $FDV; } } } unset($Folders[$FK]); } if(count($Folders) === 0) { return true; } else { $this->ScanFolders($Folders); } } private function CreateTreeFolder($Folder, $ParentFolder) { if(is_string($Folder)) { return '<ul><li><img src="slike_izgled/directory.png" width="20" height="20"> <span class="toggle">' . $Folder . '</span>'; } elseif(is_array($Folder)) { $Return = ''; foreach($Folder as $TFK => $TFV) { if(is_array($TFV)) { $Return .= $this->CreateTreeFolder($TFK, $ParentFolder); $Return .= $this->CreateTreeFile($TFV, $ParentFolder . '/' . $TFK); $Return .= '</li></ul>'; } else { $Return .= $this->CreateTreeFile($TFV, $ParentFolder); } } return $Return; } else { return ''; } } private function CreateTreeFile($File, $Folder) { if(is_string($File)) { return '<li><input type="checkbox" name="delfile[]" value="' . $this->FilePath . '/' . $Folder . '/' . $File . '"/><a href="' . $this->FilePath . '/' . $Folder . '/' . $File . '"><img src="slike_izgled/file.png"> ' . $File . '</a></li>'; } elseif(is_array($File)) { $Return = ''; foreach($File as $TFK => $TFV) { $Return .= '<li><input type="checkbox" name="delfile[]" value="' . $this->FilePath . '/' . $Folder . '/' . $TFV . '"/><a href="' . $this->FilePath . '/' . $Folder . '/' . $TFV . '"><img src="slike_izgled/file.png"> ' . $TFV . '</a></li>'; } return $Return; } } public function CreateTree() { $Return = '<ul>'; $Return .= $this->CreateTreeFolder($this->FilePath, $this->FilePath); foreach($this->TreeData[$this->FilePath] as $TK => $TV) { if(is_array($TV)) { $Return .= '<ul><li><img src="slike_izgled/directory.png" width="20" height="20"> <span class="toggle">' . $TK . '</span>'; $Return .= $this->CreateTreeFolder($TV, $TK); $Return .= '</li></ul>'; } else { $Return .= $this->CreateTreeFile($TV, $TK); } } $Return .= '</ul>'; return $Return; } public function __destruct() { return true; } } $CT = new createTree($diro); if(isset($_POST['filedel'])) { $Response = ''; if(isset($_POST['delfile']) && !empty($_POST['delfile']) && is_array($_POST['delfile']) && count($_POST['delfile']) > 0) { foreach($_POST['delfile'] as $DFK => $DFV) { $Response .= $CT->deleteFile($DFV) . '<br />'; } } else { $Response = 'Please select a file to delete.'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery Drop Down Menu</title> <link rel="stylesheet" href="stylee.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <script type="text/javascript" src="jquery.color.js"></script> <script type="text/javascript" src="jMenu.js"></script> </head> <body> <div id="jQ-menu"> <b><?php echo $Response; ?></b> <!--- osnovni_dokumenti.php?id=</?php echo $data['ideo']; ?> ---> <form action="#" method="post"> <?php echo $CT->CreateTree(); ?> <p align='center'> <input type="submit" name="filedel" value="Delete" /> </p> </form> </div> </body> </html> <?php } ?> James. DANKE ! Quote Link to comment https://forums.phpfreaks.com/topic/246286-jquery-directory-tree-check-box-delete-form/#findComment-1265138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.