Current location: Hot Scripts Forums » Programming Languages » PHP » Session array and diplaying images on other file


Session array and diplaying images on other file

Reply
  #1 (permalink)  
Old 04-19-09, 11:33 PM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 64
Thanks: 1
Thanked 0 Times in 0 Posts
Post Session array and diplaying images on other file

Good day to you all,
Session are always fun, this time I pushing 2 array to a session, one a list of folder and the other a list of files :

PHP Code:

<?php

session_start
(); 

?>




function ahah(url, target) {
  document.getElementById(target).innerHTML = ' Retreiving and loading image... <br/> Recherche et chargement de l\'image...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function load(name, div) {
    ahah(name,div);
    return false;
}



//  End -->
</script>



</head>

<body bgcolor="#ffffff" align="center" link="white" vlink="#cccccc" text="white">




<table valign="top">
<tr><td width="150px" valign="top">


<div
style="position:relative; 
 width:300px;
 height:480px;
 padding:0px;
padding-left:0px; 
padding-top:0px; 
 border-size:1px;
border-color:#000000; 
 overflow:auto;">

<?php
 
$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=\"#\" 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=\"#\" 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=\"#\" 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($file0, -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>';}
 
 
    }
    }
 
    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;\">&nbsp;".$file_modified[$key]."</a></li>\n"//echo the file name enclosed in a list item
    
}
 
 
    echo 
"</ul>\n"//close the unordered list
}
       
$_SESSION['folders']=$folders;  
       
$_SESSION['files']=$files;  

dirList($directory);
When you click on a folder it bring
you to a page like that :


PHP Code:




<?PHP
session_start
(); 
$file $_GET['file'];
$dir $_GET['dir'];

?>



<html>
<head>

    <SCRIPT language="JavaScript">
    <!--
    if (document.images)
    {
      preload_image = new Image(25,25); 
      preload_image.src="http://test.peuplies.info/PHP/Photos_gallery/<?PHP echo $dir."".$file?>"; 
    }
    //-->
    </SCRIPT>
  


</head>
<body>


<?PHP

$dir 
$_GET['dir'];
$file $_GET['file'];
echo 
"<center><img src=\"".$dir."".$file."\" width=\"400px\"/></center>"


?>





</body>
</html>
How can I list the image in that folder reading from the session array the folder passed thru the url ?

Thanks !
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array diplaying Folder on top ? peuplarchie PHP 1 04-08-09 07:15 PM


All times are GMT -5. The time now is 08:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.