T14 PHP MySQL Image Gallery

21
PHP MySQL Image Gallery

Transcript of T14 PHP MySQL Image Gallery

Page 1: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 1/21

PHP MySQL Image Gallery

Page 2: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 2/21

 The admin section contain the following :

 Add New Album

 Album List

Edit & Delete Album  Add Image

Image List

Edit & Delete Image

Page 3: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 3/21

 And the visitor page contain these :

Display Album List

Display Image List

Display Image Detail

Page 4: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 4/21

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

Page 5: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 5/21

Database Design

CREATE TABLE tbl_album (al_id INT NOT NULL AUTO_INCREMENT,al_name VARCH AR(64) NOT NULL,al_description TEXT NOT NULL,al_image VARCH AR(64) NOT NULL,al_date DATETIME NOT NULL,

PR

IMARY

KEY

(al_id));

Page 6: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 6/21

CREATE TABLE tbl_image (im_id INT NOT NULL AUTO_INCREMENT,im_album_id INT NOT NULL,

im_title VARCH AR(64) NOT NULL,im_description TEXT NOT NULL,im_type VARCH AR(30) NOT NULL,im_image VARCH AR(60) NOT NULL,

im_thumbnail VARCH

 AR

(60) NOT NULL,im_date DATETIME NOT NULL,PRIMARY KEY(im_id));

Page 7: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 7/21

Directory Layout

Page 8: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 8/21

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

save the images.

Page 9: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 9/21

Config.php

Source : Open config.doc

There are some constants in the config filethat you should change :

 ALBUM_IMG_DIR, GALLERY _IMG_DIRThese are the absolute path to the imagesdirectories

THUMBNAIL_WIDTH

The PHP script will create a thumbnail ( icons )for each image that you upload. In addition whenyou add an album image that image will alsoresized automatically.

Page 10: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 10/21

One more note. If you want to test this gallery onyour own computer please make sure you alreadyhave GD library installed. To check if GD library isinstalled on your system save the following code

and run it. <?php

if (function_exists('imagecreate')) {echo 'OK, you already have GD library installed';

} else {

echo 'Sorry, it seem that GD library is notinstalled/enabled';}?> 

Page 11: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 11/21

Image Gallery Administration Page

Login

Source : open login.doc

Page 12: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 12/21

Logout.php

<?phprequire_once '../library/config.php';

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

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

Page 13: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 13/21

 Admin Page Layout

Source : open admin-index.php

Page 14: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 14/21

 Admin : Add New Album

This is a very simple form where you canenter the album name, description andimage. 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

Page 15: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 15/21

Interface add new album

Source : open add-album.doc

Page 16: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 16/21

 Admin : Album List

Page 17: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 17/21

Modify & Delete Album

Source : open modify-album.doc

Page 18: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 18/21

Delete Album

The code for deleting an album is located inthe index.php file. The code flow is like this :

Get the album id

Make a query to get the name of that album andthe thumbnail filename. Print an error message if the album doesn't exist

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

Delete the album data and the images from thedatabase

Page 19: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 19/21

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_albumWHERE al_id = $albumId")

Page 20: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 20/21

 Album List

Page 21: T14 PHP MySQL Image Gallery

8/6/2019 T14 PHP MySQL Image Gallery

http://slidepdf.com/reader/full/t14-php-mysql-image-gallery 21/21