0

Hi Experts!

Following mentioned code, displays the thumbs images in the out of series sorting, the files in the directory are copied by using the numeric code, e.g. 1.jpg, and 2.jpg .. onwards, if exports can change a code, in order to help out, that the script display the images 1.jpg and 2.jpg in series, am not a expert, and totally new to the programming, it is absolutely helpful if someone can edit the lines.


DEMO: www.regionaltimes.com

<?php
	# SETTINGS
	$max_width = 200;
	$max_height = 200;
	$per_page = 10;
	
	$page = $_GET['page'];
	
	$has_previous = false;
	$has_next = false;
	
	function getPictures() {
		global $page, $per_page, $has_previous, $has_next;
		if ( $handle = opendir(".") ) {
			$lightbox = rand();
			echo '<ul id="pictures">';
			
			$count = 0;
			$skip = $page * $per_page;
			
			if ( $skip != 0 )
				$has_previous = true;
			
			while ( $count < $skip && ($file = readdir($handle)) !== false ) {
				if ( !is_dir($file) && ($type = getPictureType($file)) != '' )
					$count++;
			}
			$count = 0;
			while ( $count < $per_page && ($file = readdir($handle)) !== false ) {
				if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
					if ( ! is_dir('thumbs') ) {
						mkdir('thumbs');
					}
					if ( ! file_exists('thumbs/'.$file) ) {
						makeThumb( $file, $type );
					}
					echo '<li><a href="'.$file.'" rel="lightbox['.$lightbox.']">';
					echo '<img src="thumbs/'.$file.'" alt="" />';
					echo '</a></li>';
					$count++;
				}
			}
			echo '</ul>';
			
			while ( ($file = readdir($handle)) !== false ) {
				if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
					$has_next = true;
					break;
				}
			}
		}
	}
	
	function getPictureType($file) {
		$split = explode('.', $file); 
		$ext = $split[count($split) - 1];
		if ( preg_match('/jpg|jpeg/i', $ext) ) {
			return 'jpg';
		} else if ( preg_match('/png/i', $ext) ) {
			return 'png';
		} else if ( preg_match('/gif/i', $ext) ) {
			return 'gif';
		} else {
			return '';
		}
	}
	
	function makeThumb( $file, $type ) {
		global $max_width, $max_height;
		if ( $type == 'jpg' ) {
			$src = imagecreatefromjpeg($file);
		} else if ( $type == 'png' ) {
			$src = imagecreatefrompng($file);
		} else if ( $type == 'gif' ) {
			$src = imagecreatefromgif($file);
		}
		if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {
			$newW = $oldW * ($max_width / $oldH);
			$newH = $max_height;
		} else {
			$newW = $max_width;
			$newH = $oldH * ($max_height / $oldW);
		}
		$new = imagecreatetruecolor($newW, $newH);
		imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
		if ( $type == 'jpg' ) {
			imagejpeg($new, 'thumbs/'.$file);
		} else if ( $type == 'png' ) {
			imagepng($new, 'thumbs/'.$file);
		} else if ( $type == 'gif' ) {
			imagegif($new, 'thumbs/'.$file);
		}
		imagedestroy($new);
		imagedestroy($src);
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UFT-8" />
<title>Pictures</title>

<style type="text/css">
body {


}
#pictures li {
	float:left;
	height:<?php echo ($max_height + 10); ?>px;
	list-style:none outside;
	width:<?php echo ($max_width + 10); ?>px;
	text-align:center;
}
img {
	border:0;
	outline:none;
}
.prev {
	float:left;
}
.next {
	float:right;
}
</style>
</head>
<body>
<?php getPictures(); ?>
<div align="left"></div>
<div align="left" style="clear:both"></div>
<?php
	if ( $has_previous )
		echo '<p class="prev"><a href="?page='.($page - 1).'">&larr; Previous Page</a></p>';

	if ( $has_next )
		echo '<p class="next"><a href="?page='.($page + 1).'">Next Page &rarr;</a></p>';
?>
<div align="left"></div>
<div align="left" style="clear:both"></div>
<div align="left">
  <script type="text/javascript" src="js/prototype.js"></script>
  <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
  <script type="text/javascript" src="js/lightbox.js"></script>
</div>
</body>
</html>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

Attachments
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Welcome to Daily Regional Times Online Newspaper</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" class="cat_title" onLoad="MM_CheckFlashVersion('7,0,0,0','Content on this page requires a newer version of Macromedia Flash Player. Do you want to download it now?');">
<table width="974" border="0" align="center" cellpadding="3" cellspacing="15">
  <tr>
    <td width="27%" height="67"><img src="images/logo.jpg" width="365" height="37"><br>
      <span class="title">Uniting People Everyday</span> </td>
    <td width="73%"><div align="center">
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="468" height="60">
          <param name="movie" value="samaa.swf">
          <param name="quality" value="high">
          <embed src="samaa.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="468" height="60"></embed></object>
      </div></td>
  </tr>
</table>
<div align="center"> 
  <table width="905" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td width="901" height="18" bgcolor="#333333"><table width="100%" border="0" cellspacing="5" cellpadding="0">
          <tr> 
            <td width="67%" height="49"> <p><strong><font color="#FFFFFF">Sunday 
                - March, 20 - 2011 Islamic Year: 1431 A.H - </font></strong></p>
            </td>
            <td width="33%"><div align="center"><?php include('backissue.php'); ?></div></td>
          </tr>
        </table></td>
    </tr>
    <tr> 
      <td height="347" bgcolor="#EBEBEB"><table width="100%" height="482" border="0" cellpadding="0" cellspacing="7">
          <tr> 
            <td width="65%" height="468" class="field"> <div align="center"> 
                <p><br>
                  <font size="+5" face="Geneva, Arial, Helvetica, sans-serif"> 
                  </font> <br>
                  <? include ('preview.php'); ?>
                </p>
                <p>&nbsp;</p>
                <p>&nbsp; </p>
                <p align="left"><span class="commenttext"><strong>Contact Details:</strong><br>
                  Daily Regional Times<br>
                  6/1-E, Mohammad Ali Society, Karachi - Pakistan<br>
                  0092-21-34398762<br>
                  0092-21-34398763 (FAX)<br>
                  email: editor@regionaltimes.com<br>
                  <br>
                  <strong>Marketing Contact Details:</strong><br>
                  Daily Regional Times<br>
                  6/1-E, Mohammad Ali Society, Karachi - Pakistan<br>
                  0092-21-34536906 / 07<br>
                  0092-21-34398763 (FAX)<br>
                  email: marketing@regionaltimes.com </span></p>
              </div>
              <div align="center">
<div data-orient="left" data-canzoom="no" style="width:960px; height:300px;"></div>
              </div></td>
          </tr>
        </table>
        
      </td>
    </tr>
    <tr>
      <td height="18" bgcolor="#EBEBEB"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#333333">
          <tr> 
            <td height="49">
<div align="center" class="authors style1"><font color="#FFFFFF">Designed by WEBSOL.BIZ 
                </font></div></td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  
</div>
</body>
</html>
<?php
	# SETTINGS
	$max_width = 200;
	$max_height = 200;
	$per_page = 10;
	
	$page = $_GET['page'];
	
	$has_previous = false;
	$has_next = false;
	
	function getPictures() {
		global $page, $per_page, $has_previous, $has_next;
		if ( $handle = opendir(".") ) {
			$lightbox = rand();
			echo '<ul id="pictures">';
			
			$count = 0;
			$skip = $page * $per_page;
			
			if ( $skip != 0 )
				$has_previous = true;
			
			while ( $count < $skip && ($file = readdir($handle)) !== false ) {
				if ( !is_dir($file) && ($type = getPictureType($file)) != '' )
					$count++;
			}
			$count = 0;
			while ( $count < $per_page && ($file = readdir($handle)) !== false ) {
				if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
					if ( ! is_dir('thumbs') ) {
						mkdir('thumbs');
					}
					if ( ! file_exists('thumbs/'.$file) ) {
						makeThumb( $file, $type );
					}
					echo '<li><a href="'.$file.'" rel="lightbox['.$lightbox.']">';
					echo '<img src="thumbs/'.$file.'" alt="" />';
					echo '</a></li>';
					$count++;
				}
			}
			echo '</ul>';
			
			while ( ($file = readdir($handle)) !== false ) {
				if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
					$has_next = true;
					break;
				}
			}
		}
	}
	
	function getPictureType($file) {
		$split = explode('.', $file); 
		$ext = $split[count($split) - 1];
		if ( preg_match('/jpg|jpeg/i', $ext) ) {
			return 'jpg';
		} else if ( preg_match('/png/i', $ext) ) {
			return 'png';
		} else if ( preg_match('/gif/i', $ext) ) {
			return 'gif';
		} else {
			return '';
		}
	}
	
	function makeThumb( $file, $type ) {
		global $max_width, $max_height;
		if ( $type == 'jpg' ) {
			$src = imagecreatefromjpeg($file);
		} else if ( $type == 'png' ) {
			$src = imagecreatefrompng($file);
		} else if ( $type == 'gif' ) {
			$src = imagecreatefromgif($file);
		}
		if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {
			$newW = $oldW * ($max_width / $oldH);
			$newH = $max_height;
		} else {
			$newW = $max_width;
			$newH = $oldH * ($max_height / $oldW);
		}
		$new = imagecreatetruecolor($newW, $newH);
		imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
		if ( $type == 'jpg' ) {
			imagejpeg($new, 'thumbs/'.$file);
		} else if ( $type == 'png' ) {
			imagepng($new, 'thumbs/'.$file);
		} else if ( $type == 'gif' ) {
			imagegif($new, 'thumbs/'.$file);
		}
		imagedestroy($new);
		imagedestroy($src);
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UFT-8" />
<title>Pictures</title>

<style type="text/css">
body {


}
#pictures li {
	float:left;
	height:<?php echo ($max_height + 10); ?>px;
	list-style:none outside;
	width:<?php echo ($max_width + 10); ?>px;
	text-align:center;
}
img {
	border:0;
	outline:none;
}
.prev {
	float:left;
}
.next {
	float:right;
}
</style>
</head>
<body>
<?php getPictures(); ?>
<div align="left"></div>
<div align="left" style="clear:both"></div>
<?php
	if ( $has_previous )
		echo '<p class="prev"><a href="?page='.($page - 1).'">&larr; Previous Page</a></p>';

	if ( $has_next )
		echo '<p class="next"><a href="?page='.($page + 1).'">Next Page &rarr;</a></p>';
?>
<div align="left"></div>
<div align="left" style="clear:both"></div>
<div align="left">
  <script type="text/javascript" src="js/prototype.js"></script>
  <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
  <script type="text/javascript" src="js/lightbox.js"></script>
</div>
</body>
</html>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by diafol
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.