Peuplarchie Posted April 20, 2009 Share Posted April 20, 2009 Good day all, I guess I'll simplified my question : Sorry for the ones that saay that I'm repeating. I have an array of file and folder that I push to session arrays like that : <?php $session_start(); $directory = "Art/"; function dirList ($directory) { //create 2 arrays - one for folders and one for files $folders = array(); $files = array(); // create a handler for the directory $handler = opendir($directory); // keep going until all files in directory have been read while (false !== ($file = readdir($handler))) { // if $file isn't this directory or its parent, // add it to the results array if ($file != '.' && $file != '..') // If file is directory, mark it in bold. if(is_dir($directory.$file)) { array_push($folders,$file); if (time() - filemtime($directory.$file) < 604800) { $folder_modified[] = "<span style=\"color:#DB1212;\"><img src=\"minus_icon.gif\" id=\"plusminusimg".preg_replace('/\//','_',$directory."".$file)."\" onclick=\"Toggle('".preg_replace('/\//','_',$directory."".$file)."'); return false;\" /><a href=\"#\" style=\"color:#DB1212;\" onclick=\"load('folder_view.php?dir=".$directory."&file=".$file."','boxdisp');return false;\"><b>".$file."</b></a>"; } elseif (time() - filemtime($directory.$file) < 31556926) { $folder_modified[] = "<span style=\"color:#003366;\"><img src=\minus_icon.gif\" id=\"plusminusimg".preg_replace('/\//','_',$directory."".$file)."\" onclick=\"Toggle('".preg_replace('/\//','_',$directory."".$file)."'); return false;\" /><a href=\"#\" style=\"color:#003366;\" onclick=\"load('folder_view.php?dir=".$directory."&file=".$file."','boxdisp');return false;\"><b>".$file."</b></a>"; } else {$folder_modified[] = "<span style=\"color:#000000;\"><img src=\"minus_icon.gif\" id=\"plusminusimg".preg_replace('/\//','_',$directory."".$file)."\" onclick=\"Toggle('".preg_replace('/\//','_',$directory."".$file)."'); return false;\" /><a href=\"#\" style=\"color:#000000;\" onclick=\"load('folder_view.php?dir=".$directory."&file=".$file."','boxdisp');return false;\"><b>".$file."</b></a>";} // Else not styled }else{ array_push($files,$file); $filenamecor = substr($file, 0, -4); if (time() - filemtime($directory.$file) < 604800) { $file_modified[] = '<span style="color:#DB1212;">'.$filenamecor.'<span>'; } elseif (time() - filemtime($directory.$file) < 31556926) { $file_modified[] = '<span style="color:#003366;">'.$filenamecor.'<span>'; } else {$file_modified[] = '<span style="color:#000000;">'.$filenamecor.'<span>';} } } $_SESSION['folders']=$folders; $_SESSION['files']=$files; echo "<ul id=\"".preg_replace('/\//','_',substr($directory,0,strlen($directory)-1))."\">\n"; //start a new unordered list for every iteration through dirList $dircor = $directory; // tidy up: close the handler closedir($handler); foreach($folders as $folder=>$file) { echo "<li id=\"pic\"><div class=\"folder\">".$folder_modified[$folder]."</div>"; //echo the folder name enclosed in a list item dirList($directory.$file.'/'); //loop through the contents of $folder echo "</li>\n"; //close this list item after all files and folders in $folder have been looped through } foreach($files as $key=>$file) { echo "<li id=\"pic\"><a href=\"index.html\" onclick=\"load('image_view.php?dir=".$dircor."&file=".$file."','boxdisp');return false;\"> ".$file_modified[$key]."</a></li>\n"; //echo the file name enclosed in a list item } echo "</ul>\n"; //close the unordered list } dirList($directory); ?> </div> Now, like you can see , each file and folders are links. I have no problem looking at the files, but for the folder I should be able to see all the file in that directory, non recursively listed from the arrays like here is my code now : <?PHP session_start(); $dir = $_GET['dir']; $file = $_GET['file']; foreach($_SESSION['folders'] as $role ) { echo $role; } echo "<br>"; ?> Thnaks ! Quote Link to comment https://forums.phpfreaks.com/topic/154830-list-part-of-the-session-array-from-a-link/ Share on other sites More sharing options...
mtoynbee Posted April 20, 2009 Share Posted April 20, 2009 As far as I know you cannot store arrays in a session. Therefore the stored values of 'files' will be just the word Array. You should be able to get around this by serializing the array first. See PHP Manual serialize() function for more information: http://uk.php.net/serialize Quote Link to comment https://forums.phpfreaks.com/topic/154830-list-part-of-the-session-array-from-a-link/#findComment-814297 Share on other sites More sharing options...
Peuplarchie Posted April 20, 2009 Author Share Posted April 20, 2009 because I cannot use a database for this site. Quote Link to comment https://forums.phpfreaks.com/topic/154830-list-part-of-the-session-array-from-a-link/#findComment-814503 Share on other sites More sharing options...
mtoynbee Posted April 24, 2009 Share Posted April 24, 2009 Who said anything about databases? Quote Link to comment https://forums.phpfreaks.com/topic/154830-list-part-of-the-session-array-from-a-link/#findComment-818162 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.