php mysql image gallery. the admin section contain the following : add new album album list edit...

21
PHP MySQL Image Gallery

Upload: joella-white

Post on 03-Jan-2016

229 views

Category:

Documents


1 download

TRANSCRIPT

PHP MySQL Image Gallery

The admin section contain the following : Add New Album Album List Edit & Delete Album Add Image Image List Edit & Delete Image

And the visitor page contain these : Display Album List Display Image List Display Image Detail

Now, before we go straight to the codes we need to talk about the database design, directory layout, and configurations.

Database Design

CREATE TABLE tbl_album (al_id INT NOT NULL AUTO_INCREMENT,al_name VARCHAR(64) NOT NULL,al_description TEXT NOT NULL,al_image VARCHAR(64) NOT NULL,al_date DATETIME NOT NULL,PRIMARY KEY(al_id));

CREATE TABLE tbl_image (im_id INT NOT NULL AUTO_INCREMENT,im_album_id INT NOT NULL,im_title VARCHAR(64) NOT NULL,im_description TEXT NOT NULL,im_type VARCHAR(30) NOT NULL,im_image VARCHAR(60) NOT NULL,im_thumbnail VARCHAR(60) NOT NULL,im_date DATETIME NOT NULL,PRIMARY KEY(im_id));

Directory Layout

The images directory is where we kept all of the images. The image icons are stored in the thumbnail sub-directory uder the gallery. Please remember to set write access to the album, gallery, and thumbnail directories otherwise the gallery script will not be able to save the images.

Config.php

Source : Open config.doc There are some constants in the config file

that you should change : ALBUM_IMG_DIR, GALLERY_IMG_DIR

These are the absolute path to the images directories

THUMBNAIL_WIDTHThe PHP script will create a thumbnail ( icons ) for each image that you upload. In addition when you add an album image that image will also resized automatically.

One more note. If you want to test this gallery on your own computer please make sure you already have GD library installed. To check if GD library is installed on your system save the following code and run it.

<?phpif (function_exists('imagecreate')) {   echo 'OK, you already have GD library installed';} else {   echo 'Sorry, it seem that GD library is not installed/enabled';}?>

Image Gallery Administration Page Login Source : open login.doc

Logout.php<?php require_once '../library/config.php';

// To logout we only need to set the value of isLogin to false $_SESSION['isLogin'] = false;

header('Location: login.php'); exit; ?>

Admin Page Layout

Source : open admin-index.php

Admin : Add New Album

This is a very simple form where you can enter the album name, description and image. After you click the "Add Album" button the script will do the followings :

Save the album image, resize it if necessary Save the album information to database

Interface add new album

Source : open add-album.doc

Admin : Album List

Modify & Delete Album

Source : open modify-album.doc

Delete Album

The code for deleting an album is located in the index.php file. The code flow is like this : Get the album id Make a query to get the name of that album and

the thumbnail filename. Print an error message if the album doesn't exist

If the album exist get images file name and delete the images plus the album icon

Delete the album data and the images from the database

Source delete : lihat admin-index.doc // ... some code on top if

(isset($_GET['deleteAlbum']) && isset($_GET['album']) ) {   $albumId = $_GET['album'];

   // get the album name since we need to display   // a message that album 'foo' is deleted   $result = mysql_query("SELECT al_name, al_image                          FROM tbl_album                           WHERE al_id = $albumId")

Album List