ShowPhoto.php - Simple Slid Show Script

This section provides a tutorial example on how to display image files in a directory in a slide show format. The getimagesize() function is used to retrieve image sizes from image files.

Another nice function for image file management is the "get image size" function, getimagesize($path), which returns the size and other information about the image stored in a file located at $path.

To show you how to use this getimagesize() function, I wrote the following sample script:

#  PhotoShow.php
#- Copyright 2009-2015 (c) All Rights Reserved.
#- Get the photo file name
   $i = intval($_GET['i']);
   $c = 0;
   $p = "";
   if ($d = opendir(".")) {
      while (($f = readdir($d)) != false) {
         if (preg_match('/.jpg$/',$f)) {
            if ($i==$c) {
               $p = $f;

#- Build the page
   $h = fopen("header.html", "r");
   $s = fread($h, filesize("header.html"));
   print "$s\n";

   if (strlen($p)>0) {
      $i1 = ($i+$c-1) % $c;
      $i2 = ($i+$c+1) % $c;
      list($width, $height, $type, $attr) = getimagesize($p);
      if ($width>700) {
         $width = $width/2;
         $height = $height/2;
      print "<center><a href=\"ShowPhoto.php?i=$i1\"><=</a>&nbsp;"
         ."<a href=\"ShowPhoto.php?i=$i2\">=></a></center>\n"
         ."<center><img src=\"$p\" border=\"1\" width=\"$width\" "
         ."<center><a href=\"ShowPhoto.php?i=$i1\"><=</a>&nbsp;"
         ."<a href=\"ShowPhoto.php?i=$i2\">=></a></center>\n";
   } else {
      print "<p>Wrong URL. Please go back to the home page.</p>\n";

   $h = fopen("footer.html", "r");
   $s = fread($h, filesize("footer.html"));
   print "$s\n";

This script will display image files stored in a directory one image at a time like a slideshow.

Try it out. It's very easy to use. You can easily customize it to meet your requirements.

Table of Contents

 About This Book

 Introduction and Installation of PHP

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Interface with Operating System

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 Managing File Upload

 MySQL Server Connection and Access Functions

Functions to Manage Directories, Files and Images

 opendir() and Directory Management Functions

 file_exists() and File Testing Functions

 FileExistsTest.php - File Testing Examples

 fopen() and File Input/Output Functions

 File_Input_Output_Test.php - File Input/Output Examples

 readfile() and Special File Handling Functions

ShowPhoto.php - Simple Slid Show Script

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Parsing and Managing HTML Documents

 Configuring and Sending Out Emails

 Image and Picture Processing

 Managing ZIP Archive Files

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 Archived Tutorials


 Full Version in PDF/EPUB