A Digital Age Deserves A Digital Leader

php Help?

php Help?

Postby c0ldfyr3 » Sat Jan 19, 2008 1:03 am

i want to add highlside to my current image script... but i need some help i have been working on this for some time now and had no luck integrating it...

this is what i currently have....

Code: Select all

##############################################################
#ASCENDED MINI GALLERY BETA 0.0.2
##############################################################
error_reporting(0); //0 to turn off error reporting

//This might set the memory limit to 40MB
//Notice not every host allow you to do this, so it
//Might not work. We reccommend using at least 36MB to the gallery
//as one picture need more memory than the file size in itself (It needs to be uncompressed)
ini_set('memory_limit', '36M');

//NOTICE. If the gallery run slow you could call
//http://pathtothe/index.php?do=cache
//This would verbosly cache the located pictures.


//CONFIGURATION
$CONFIG['nameOfAlbum'] = 'Portfolios';

//You could include all found albums in the folder present to the index.php
//Set "allowAllDirs" to true if you want to include all (then you dont need to enter anything in albums)
//Set it to false if you want to specify the albums you want to include yourself.

$CONFIG['allowAllDirs'] = true;  //Allow all dirs located at the root-folder?
//If you dont want the system to include all folders, enter the folder names you want below,
//Remember to set "allowAllDirs" to false.
$CONFIG['albums'] = array('');
//What extensions to allow. Only enter lower case extensions.
//If you enter jpg, altso JPG would get accepted.
$CONFIG['allowedExtensions'] = array('jpg', 'jpeg', 'gif', 'png');
//What would the name of the cache folder be
//We would reccomend to keep this to "cache"
$CONFIG['cacheFolderName'] = 'cache'; //Name of the temp folder


//If you get "ugly" pictures, you can increase the quality here.
//This will _only_ work on .jpg/.jpeg-pictures
//Notice that 100 in quality will make large and slow loading images. (reccomending about 85)
$CONFIG['imageQuality'] = 85;

$CONFIG['thumbX'] = 85; //Width of the thumbs
$CONFIG['thumbY'] = 85; //Height of the thumbs
$CONFIG['fullX'] = 600; //Width of the full picture
$CONFIG['thumbsInwidth'] = 5; //How many thumbs in width in the browsing.
$CONFIG['chmod'] = 0777; //How many thumbs in width in the browsing.
$CONFIG['resizeUp'] = true //If the image is smaller, do you want it to resize up? (The image might  look zoomed). (true = zoom, false = do not zoom)


//END CONFIGURATION

?>

<DOCTYPE>
<html>
<head>
<meta>
<title><php></title>
<style type="text/css">
</CSS>
</style>
</head>
<body>
<div class="container">
<h2 class="header"><php></h2>
<p class="subheader">
<?php

//If all albums are allowd, fetch all albums in the folder, and use them as albums.
if ($CONFIG['allowAllDirs'] || empty($CONFIG['albums'])){
      $CONFIG['albums'] = array();
      if (is_dir('.')) {
            if ($dh = opendir('.')) {
              while (($file = readdir($dh)) !== false) {
                   if (is_dir($file) && $file !== '..' && $file !== '.' && $file != $CONFIG['cacheFolderName']) $CONFIG['albums'][] = $file;
                }
               
             closedir($dh);
            }
   
      }
}
sort($CONFIG['albums']);
//Check for content in the album
$countAlbums = count($CONFIG['albums']);

//Create the folders for the albums

if (file_exists($CONFIG['cacheFolderName']) && is_dir($CONFIG['cacheFolderName'])){
   if (!is_writable($CONFIG['cacheFolderName'])) die("Can't write to the folder ".$CONFIG['cacheFolderName']);   
} else {
   if(!mkdir($CONFIG['cacheFolderName'])) echo 'Could not create the cache folder. No access';
   elseif(!chmod($CONFIG['cacheFolderName'], $CONFIG['chmod'])) echo 'Could not chmod the cache folder. No access';
}//END CREATING CACHE FOLDER.



//Building the navigation
$home = '<a href="index.php">Gallery home</a>';
if (@isset($_GET['album']) && !isset($_GET['img'])) $album = ' | '.$_GET['album'].'';
if (@isset($_GET['album'])&& isset($_GET['img'])) $album = ' | <a href="index.php?album='.$_GET['album'].'">'.$_GET['album'].'</a>';
if (@isset($_GET['album'])&& isset($_GET['img'])) $img = ' | '.$_GET['img'].'';
if (@!isset($_GET['album']) && !isset($_GET['do'])) $home = 'Gallery home';
echo @$home.@$album.@$img.'';
//End navigation




if (@$_GET['do'] == 'cache'){
   ob_implicit_flush(true);
   $sec = @ini_get('max_execution_time') / 100 * 80; //Working 80% inside the limit
   header("Refresh: ".$sec.";URL=".$_SERVER['PHP_SELF']."?do=cache");
   ob_flush();
   echo '<h3>Picture caching. This can take some time to complete...</h3><br>';
      //Load the pictures from the album
      for ($i = 0; $i < $countAlbums; $i++){
         //Check the cache for the albums, and cache the pictures in the folder.
         if (!file_exists($CONFIG['cacheFolderName'].'/'.$CONFIG['albums'][$i]) || !is_dir($CONFIG['cacheFolderName'].'/'.$CONFIG['albums'][$i])){
            if (mkdir($CONFIG['cacheFolderName'].'/'.$CONFIG['albums'][$i])) echo '<br>Creating cache folder for the album: '.$CONFIG['albums'][$i].'<br>';
            if(!chmod($CONFIG['cacheFolderName'], $CONFIG['chmod'])) echo 'Could not chmod the cache folder. No access';
            else echo 'Cant write to disc.';
         }   
         
         echo '<b>Caching album: '.$CONFIG['albums'][$i].'</b><br>';
         
         //Fetching the files in the folder
         $files = array();
         if (is_dir($CONFIG['albums'][$i])) {
               if ($dh = opendir($CONFIG['albums'][$i])) {
                 while (($file = readdir($dh)) !== false) {
                      if (validExt($CONFIG['albums'][$i].'/'.$file)) $files[] = $file;
                   }
                closedir($dh);
               }
         }
      
      
      $countFiles = count($files);
   ob_flush();
         for ($j = 0; $j <countFiles>= 0){
         
            echo 'Caching the picture: '.$files[$j].': ';
            echo 'Creating thumbnail: ... ';
            createThumb($files[$j], $files[$j], $CONFIG['albums'][$i]);
            echo 'Creating image: ...<br><br>';
            createImg($files[$j], $files[$j], $CONFIG['albums'][$i]);
            ob_flush();
         }
      }
      
      
   }
   echo '<b>Caching complete</b>';
   //END MANUAL CACHING
   
}else{

//Cache one picture on each album to create the thumbnails.

if (!isset($_GET['album'])){
   for ($i = 0; $i < $countAlbums; $i++){
      //Check the cache for the albums, and cache the pictures in the folder.
      if (!file_exists($CONFIG['cacheFolderName'].'/'.$CONFIG['albums'][$i]) || !is_dir($CONFIG['cacheFolderName'].'/'.$CONFIG['albums'][$i])){
         if (!mkdir($CONFIG['cacheFolderName'].'/'.$CONFIG['albums'][$i])) echo 'Cant create the cache directory. Cant write to disc.';
         if (!chmod($CONFIG['cacheFolderName'].'/'.$CONFIG['albums'][$i], $CONFIG['chmod'])) echo 'Cant chmod the cache directory. Cant write to disc.';
      }
   
      //Load the pictures from the album
      $files = array();
      if (is_dir($CONFIG['albums'][$i])) {
            if ($dh = opendir($CONFIG['albums'][$i])) {
              while (($file = readdir($dh)) !== false) {
                   if (validExt($CONFIG['albums'][$i].'/'.$file)) $files[] = $file;
                }
             closedir($dh);
            }
      
            $countFiles = count($files);
            
           //Caching one picture
          if (!$countFiles <0> 0 && folderContent($CONFIG['albums'][$i]) == 0){
                  if ($countFiles >= 0) createThumb($files[0], $files[0], $CONFIG['albums'][$i]);
               }
      
    
            //Show the albums
            
            echo '<div class="galleryMain" href="index.php?album='.urlencode($CONFIG['albums'][$i]).'">
            <div class="galleryMainPic"><a href="index.php?album='.urlencode($CONFIG['albums'][$i]).'"><img class="galleryMain" src="'.$CONFIG['cacheFolderName'].'/'.$CONFIG['albums'][$i].'/thumb.'.$files[0].'"></img></a></div>
            <div class="galleryMainText"><a class="galleryMainText" href="index.php?album='.urlencode($CONFIG['albums'][$i]).'">'.$CONFIG['albums'][$i].'</a></div>
            </div>';
   
         }
      }else echo 'Cant read from the album. Might be wrong access rights';
   }



}else if (isset($_GET['album'])){
   echo '<div class="galleryBrowse">';   
   //Cache all picture in this album.
   
   //Checking if the album is in the validated array
   if (in_array($_GET['album'],$CONFIG['albums'])){
         $album = $_GET['album'];
         $files = array();
      if (is_dir($album)) {
            if ($dh = opendir($album)) {
              while (($file = readdir($dh)) !== false) {
                   if (validExt($album.'/'.$file)) $files[] = $file;
                }
             closedir($dh);
            }
      }
      
      
      $countFiles = count($files);
      $num = 0;
      
      for ($i = 0; $i <countFiles>= 0){
         
          createThumb($files[$i], $files[$i], $album);
          createImg($files[$i], $files[$i], $album);
      }   
      
      if (@$_GET['do'] == 'browse' || !isset($_GET['do'])){
         
         
         if ($num == $CONFIG['thumbsInwidth']) {
            $num = 0;
            echo '<br>';
         }
         
         
         
         echo '<a href="index.php?album='.urlencode($album).'&do=view&img='.urlencode($files[$i]).'"><img class="galleryBrowse" src="'.$CONFIG['cacheFolderName'].'/'.$album.'/thumb.'.$files[$i].'"></img></a>';
         $num++;
            
      
      }
      
   }
   echo '</div>';

   if(@$_GET['do'] == 'view'){
      echo '<br><br>';
      if (in_array($_GET['img'], $files)){
         echo '<div class="galleryView">';
         echo browserPic($_GET['img'], $_GET['album']);
         echo '<a href="'.$album.'/'.$_GET['img'].'"><img class="galleryView" src="'.$CONFIG['cacheFolderName'].'/'.$album.'/full.'.$_GET['img'].'"> </img>';
         echo '</div>';
      }else echo 'Not a valid image name';      
   }
      

} //END CACHE   
   
}
}

function browserPic($pos, $album){
   $files = array();
   if (is_dir($album)) {
      if ($dh = opendir($album)) {
          while (($file = readdir($dh)) !== false) {
               if (validExt($album.'/'.$file)) $files[] = $file;
            }
      closedir($dh);
      }
   }
   
   $countFiles = count($files);
   $key = array_search($pos, $files);

   if ($key </a>= 1 && $key < $countFiles-1)
         $nav .= '<a href="index.php?album='.urlencode($album).'&do=view&img='.urlencode($files[$key-1]).'">Previous</a> | <a href="index.php?album='.$album.'&do=view&img='.$files[$key+1].'">Next</a>';
      else if ($key == $countFiles-1)
         $nav .= '<a href="index.php?album='.urlencode($album).'&do=view&img='.urlencode($files[$key-1]).'">Previous</a>';
   }
   return $nav;

}

function folderContent($in){
   global $CONFIG;
   $in = $CONFIG['cacheFolderName'].'/'.$in;

      $files = 0;
      if (is_dir($in)) {
         
            if ($dh = opendir($in)) {
               
              while (($file = readdir($dh)) !== false) {
              
                   if (detectCachePicture($file, $in)) $files++;
                }
               
          closedir($dh);
      }   
   
}
return $files;
}

function validExt($in){
global    $CONFIG;
   if (is_file($in)){
      $new = explode('.', $in);
      $count = count($new);
      //If the picture has an allowed extension
      if (in_array(strtolower($new[(int)$count-1]),$CONFIG['allowedExtensions'] ))return true;
      else return false;
   }else return false;

}

function detectCachePicture($in, $album){
global    $CONFIG;
$in = $album.'/'.$in;
   if (is_file($in)){
      $new = explode('.', $in);
      $count = count($new);
      //If the picture has an allowed extension
      if (in_array($new[(int)$count-1],$CONFIG['allowedExtensions'] ))return true;
      else return false;
   }else return false;

}

function readPicture($in){
   $fh = fopen($in, 'rb');
   $content = fread($fh, filesize($in));
   return $content;
   fclose($in);
   
}

function tempFile($in, $album){
   global $CONFIG;
   $foldername = $CONFIG['cacheFolderName'];
   if (file_exists($foldername) && is_dir($foldername)){
      if (file_exists($foldername.'/'.$album.'/thumb.'.$in)) return false;
      else return true;
      
   } else{
       mkdir($foldername);
       if (!chmod($foldername, $CONFIG['chmod'])) echo 'Cant chmod the directory. Cant write to disc';
       return true;
   }
   
   
}

function tempFileFull($in, $album){
   global $CONFIG;
   $foldername = $CONFIG['cacheFolderName'];
   if (file_exists($foldername) && is_dir($foldername)){
      if (file_exists($foldername.'/'.$album.'/full.'.$in)) return false;
      else return true;
      
   } else{
       mkdir($foldername);
       if (!chmod($foldername, $CONFIG['chmod'])) echo 'Cant chmod the directory. Cant write to disc';
       return true;
   }
   
   
}


function createThumb($in, $file, $album){
   global $CONFIG;
   if(tempFile($file, $album)){
   $tempfolder = $CONFIG['cacheFolderName'].'/'.$album;
   $in = readPicture($album.'/'.$in);
   $dim = getimagesize($album.'/'.$file);
   $image = imagecreatetruecolor($CONFIG['thumbX'], $CONFIG['thumbY']);
   $bgwidth = $dim[0];
   $bgheight = $dim[1];
   $prop = $bgwidth / $bgheight;
   $bhwidth = $CONFIG['thumbX'];
   $bgheight = $CONFIG['thumbY'] / $prop;
   if ($bgheight < $CONFIG['thumbY']) {
      $bgheight = $CONFIG['thumbY'];
      $bhwidth = $CONFIG['thumbX'] *$prop;   
   }
   
   
   
   //Make a new image from the file above
   $imagebg = imagecreatefromstring($in);
   imagecopyresized($image, $imagebg, '0', '0', '0', '0', $bhwidth, $bgheight, $dim[0], $dim[1]);
      //Outut to the correct file type.
   $new = explode('.', $file);
   $count = count($new);
   $ext = strtolower($new[(int)$count-1]);
   
   if ($ext == 'gif')
      imagegif($image, $tempfolder.'/thumb.'.$file);
   else if ($ext == 'jpg' || $ext == 'jpeg')
      imagejpeg($image, $tempfolder.'/thumb.'.$file);
   else if ($ext == 'png')
      imagepng($image, $tempfolder.'/thumb.'.$file);
   else
      imagejpeg($image, $tempfolder.'/thumb.'.$file);
      
   if (!chmod($tempfolder.'/thumb.'.$file, $CONFIG['chmod'])) echo 'Cant chmod the file. Cant write to disc';
   
   }   
}



function createImg($in, $file, $album){
   global $CONFIG;
   if(tempFileFull($file, $album)){
   $tempfolder = $CONFIG['cacheFolderName'].'/'.$album;
   $in = readPicture($album.'/'.$in);
   $dim = getimagesize($album.'/'.$file);
   $bgwidth = $dim[0];
   $bgheight = $dim[1];
      //Make a new image from the file above
   $imagebg = imagecreatefromstring($in);
   if ($CONFIG['resizeUp'] == FALSE && $bgwidth < $CONFIG['fullX']){ //Do not resize

   $image = imagecreatetruecolor($bgwidth, $bgheight);

   imagecopyresized($image, $imagebg, '0', '0', '0', '0', $bgwidth, $bgheight, $bgwidth, $bgheight);
   
   } else {
      $prop = $bgwidth / $bgheight;
   $heigth = $CONFIG['fullX'] / $prop;
   $image = imagecreatetruecolor($CONFIG['fullX'], $heigth);

   imagecopyresized($image, $imagebg, '0', '0', '0', '0', $CONFIG['fullX'], $heigth, $bgwidth, $bgheight);
   
   }
   
   //Outut to the correct file type.
   $new = explode('.', $file);
   $count = count($new);
   $ext = strtolower($new[(int)$count-1]);
   
   if ($ext == 'gif')
      imagegif($image, $tempfolder.'/full.'.$file);
   else if ($ext == 'jpg' || $ext == 'jpeg')
      imagejpeg($image, $tempfolder.'/full.'.$file, $CONFIG['imageQuality']);
   else if ($ext == 'png')
      imagepng($image, $tempfolder.'/full.'.$file);
   else
      imagejpeg($image, $tempfolder.'/full.'.$filem, $CONFIG['imageQuality']);
      
   if (!chmod($tempfolder.'/full.'.$file, $CONFIG['chmod'])) echo 'Cant chmod the file. Cant write to disc';
   }   
}


echo ' </p>
 
 
</div>
<div class="copyright"> &copy; 2006 <a class="copyright" href="http://www.ascdevel.com">Ascended Development</a>  </div>

</body>
</html>';



and i need to integrate this code into it..

Code: Select all
<a id="thumb1" href="images/gohere.jpg" class="highslide">
   <img src="images/thumbnail.jpg" alt="Highslide JS" title="Click to enlarge" height="120" width="107"></a>


the problem i am running into is the "id". currently i have to input the thumb# manually for each picture... it would be easier if there was some code to count the pictures and add that number for me. also i currently have to add that last piece of code in the index for each picture i want to show on the index. since its a gallery i think that all the pictures in the designated directory should show, thats how the first piece of code works. I create a directory and add the pictures it looks in the directory and displays the pictures... so i need the second peice of code to do its job inside the first script....
Image
PRO Level 15
User avatar
Posts: 1346
Joined: Sun May 02, 2004 8:49 pm
Location: 127.0.0.1

Postby c0ldfyr3 » Sun Jan 20, 2008 2:13 am

any ideas?
Image
PRO Level 15
User avatar
Posts: 1346
Joined: Sun May 02, 2004 8:49 pm
Location: 127.0.0.1

Postby jbullard » Sun Jan 20, 2008 3:21 am

Yes. Sorry, meant to post yesterday but got swamped at work.

The simplest idea is to use a counter. You are obviously looping through the files in order to show images inside a folder so all you would need to do is just increment that counter each time it is looped and add that as the id.

This way you never risk the chance or a duplicate random number and it cuts down on executable code.
VP - Software
User avatar
Posts: 3653
Joined: Sun Jun 06, 2004 10:17 pm
Location: Utah
Real Name: Jason Bullard

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 0 guests

cron
cron