This script reads images in your dir and displays first one with next prev buttons. No work needed just drop in dir. Also gives thumbnail option and links at bottom to each image in the dir
By : eltreno
<?php
//=========================================
//
// Author: Trent Williams
// Date: 19 Aug 2005
// EXPLAINATION
//
// A simply script to drop in any dir to display next prev buttons and current image for all your images in that dir with extentions you allow
// Uses id parameter to know what image to show next else it will show first image
// Also a number list at bottom page to go to any image, alt text displays image name
// change the colours in the styles in the html body
//which dir
$d = dir(".");
//read thru and
while (false !== ($entry = $d->read())) {
//allow extensions here
//|| preg_match("/(\.bmp$)/i", $entry)
//|| preg_match("/(\.jpeg$)/i", $entry)
if (preg_match("/(\.gif$)/i", $entry) || preg_match("/(\.jpg$)/i", $entry)){
$pics[] = $entry;
}
}
$d->close();
//================
//total images count
$numPics = count($pics);
//================
//picture in array to show on this page
$thispic = 0;
if (is_numeric($_GET['id'])){
$thispic = $_GET['id'];
}
$thispicDisplay = $thispic + 1;
//================
//img tag for current image
$thisImage = '<img src="' . $pics[$thispic] . '" alt="' . $pics[$thispic] . '" />';
//======================
// START set thumbnails on or off
//comment this section out if you don't want thumbs to show at all
$showThumbs = 5;//number of thums to show
$thumbsList = '';
$thumburl = '';
if ($_GET['thumb'] == 'yes'){
//read thumb param to url if exists
$thumburl = '&thumb=yes';
for ($i=0;$i<$showThumbs;$i++){
if ($thispic + $i + 1 < $numPics){
$currThumb = $thispic + $i + 1;
$thumbsList .= '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $currThumb . $thumburl . '" title="' . $pics[$currThumb] . '"><img src="' . $pics[$currThumb] . '" alt="' . $pics[$currThumb] . '" height="100" width="100" border="0" /></a> ';
}
}
$onOff ='<a class="thumbs" href="' . $_SERVER['PHP_SELF'] . '?id=' . $thispic . '">Turn Thumbnails Off</a>';
} else {
$onOff ='<a class="thumbs" href="' . $_SERVER['PHP_SELF'] . '?id=' . $thispic . '&thumb=yes">Turn Thumbnails On</a>';
}
// END set thumbnails on or off
//prev button
$prevurl = ' <span class="highlighted">First Picture</span>';
if ($thispic > 0){
$prev = $thispic - 1;
$prevurl = '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $prev . $thumburl . '" title="' . $pics[$prev] . '">Previous picture</a>';
}
//next button
$nexturl = ' <span class="highlighted">Last Picture</span>';
if ($thispic < ($numPics - 1)){
$next = $thispic + 1;
$nexturl = '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $next . $thumburl . '" title="' . $pics[$next] .'">Next picture</a>';
}
//=======================
// string of all pics url's
$urlarray = '';
for ($i=0;$i<count($pics);$i++){
//highlign pic you are on
$j = $i + 1;
if ($i != $thispic){
$urlarray .= '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $i . $thumburl .'" title="' . $pics[$i] . '">' . $j .'</a> ';
} else {
$urlarray .= ' <span class="highlighted">' . $j . '</span> ';
}
}
?>
<?php echo '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n"; ?>
<!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">
<head>
<title><?=$pics[$thispic]?></title>
<meta name="Author" content="Trent Williams" />
<style type="text/css">
*{margin:0px;}
html, body{color:#000; background-color:#000;}
.borders {background:#DBDE5C; border:2px solid #DF1C11; padding:10px; width:100%; float:left; font-family:arial, helvetica, sans-serif; font-size:85%;}
.content {padding:10;}
a{color:#000;text-decoration:none; font-weight:bold;}
a:hover{text-decoration:underline;}
.highlighted {color:#DF1C11; font-weight:bold;}
a.thumbs {color:#DBDE5C;text-decoration:none; font-weight:bold;}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="10" border="0">
<tr>
<td>
<div class="borders"><?=$prevurl?> | <?=$nexturl?> Picture number: <strong><?=$thispicDisplay?></strong> Picture name: <strong><?=$pics[$thispic]?></strong></div>
<div class="content"><center><?=$thisImage?></center></div>
<div class="content"><?=$onOff?><center><?=$thumbsList?></center></div>
<div class="borders"><?=$urlarray?></div>
</td>
</tr>
</table>
</body>
</html>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Site Navigation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. FREE! Go There Now!
|
|
|
|
Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. FREE! Go There Now!
|
|
|
|
Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
|
|
|
|
This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”. FREE! Go There Now!
|
|
|
|
This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |