PHP Classes

File: examples/addimages.php

Recommend this page to a friend!
  Classes of Barton Phillips   MySQL Slideshow   examples/addimages.php   Download  
File: examples/addimages.php
Role: Example script
Content type: text/plain
Description: Example script
Class: MySQL Slideshow
Present slideshow from images listed in a database
Author: By
Last change: This is a new version of mysqlslideshow. I have removed all of the class/ stuff and included it in the single file examples/mysqlslidehow.class.php.
The class file now has all of the mysqli logic in the class. It also has what was the mysqlslideshow.php logic after the class.
The other file have been modified to work better.
modified: README.md
deleted: class/Error.class.php
deleted: class/SqlException.class.php
deleted: class/dbAbstract.class.php
deleted: class/dbMysqli.class.php
deleted: class/helper-functions.php
deleted: class/mysqlslideshow.class.php
modified: composer.json
deleted: examples/ERROR.log
new file: examples/Pictures/P1010001.JPG
new file: examples/Pictures/P1010002.JPG
new file: examples/Pictures/P1010003.JPG
modified: examples/addimages.php
modified: examples/addupdateimage.php
modified: examples/browserside.html
modified: examples/dbclass.connectinfo.i.php
modified: examples/ie.html
modified: examples/mktable.sql
new file: examples/mysqlslideshow.class.php
deleted: examples/mysqlslideshow.php
modified: examples/serverside.php
Date: 1 year ago
Size: 2,231 bytes
 

Contents

Class file image Download
<?php
// Add selected images from a directory
// This file has the MySqlSlideshow class and the mysqlslideshow GET functions.

require_once("mysqlslideshow.class.php"); // instantiates $ss

// Construct the slideshow class:
// There is a 4th argument for the database name if not "mysqlslideshow" and a
// 5th argument for the table name if not "mysqlslideshow"

$self = $_SERVER["PHP_SELF"];

// Add Image

if($_POST["box"]) {
 
extract($_POST);

 
$adding = '';
 
  for(
$i=0; $i < $count; ++$i) {
   
$image = $box[$i];
    if(empty(
$image)) continue;
   
   
$tsubject = $subject[$i];
   
$tdesc = $desc[$i];

   
error_log("subject: $tsubject, desc: $tdesc");

    if((
$ret = $ss->addImage($image, $tsubject, $tdesc)) === true) {
     
$adding .= "<p>Image added: $image, subject=$tsubject, description=$tdesc</p>\n";
    } else {
     
$adding .= "<p style='color: red'>$ret</p>\n";
    }
  }

  echo <<<EOF
<!DOCTYPE html>
<html>
<body>
<h1>Added Images</h1>
$adding
</body>
</html>
EOF;
  exit();
}

// Main Page

if($path = $_POST['path']) {
 
$pattern = $_POST['pattern'];

  if(
strpos($path, "/", -1)) {
   
$path = "$path$pattern";
  } else {
   
$path = "$path/$pattern";
  }

 
$images = glob($path); // get all of the files from the directory

 
$body = <<<EOF
<h1>No Files Matched</h1>
EOF;
     
  if(
count($images)) {
   
$body = <<<EOF
<h1>Select Images</h1>
<form method="post">
EOF;
   
    for(
$i=0; $i < count($images); ++$i) {
     
$image = $images[$i];
     
$body .= <<<EOF
<input type="checkbox" name="box[$i]" value="$image"/>$image<br>
<input type="text" name="subject[
$i]" /> Subject<br>
<input type="text" name="desc[
$i]" /> Description<br>
<br>
EOF;
    }

   
$body .= <<<EOF
<input type="hidden" name="count" value="$i" />
<button>Submit</button>
</form>
</body>
</html>
EOF;
  }
}

if(!
$_POST) {
 
$body =<<<EOF
<h1>Enter Image Location</h1>
<form action="addimages.php" method="post">
<table>
<tr><th>Path to images</th><td><input type="text" name="path"></td></tr>
<tr><th>Select a pattern to match against</th><td><input type="text" name="pattern"></td></tr>
</table>
<button>Do It</button>
</form>
EOF;
}

// Render

echo <<<EOF
<!DOCTYPE html>
<html>
<body>
$body
</body>
</html>
EOF;