the following codes for 3 files is used to view images in an album. the images are coming up as red x's.
any thoughts?
list-image.php
Code: Select all
<?php
if (isset($_GET['delete']) && isset($_GET['album']) && isset($_GET['imgId'])) {
// get the image file name so we
// can delete it from the server
$sql = "SELECT im_image, im_thumbnail
FROM tbl_image
WHERE im_id = {$_GET['imgId']} AND im_album_id = {$_GET['album']}";
$result = mysql_query($sql) or die('Delete album failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
// remove the image and the thumbnail from the server
unlink(GALLERY_IMG_DIR . $row['im_image']);
unlink(GALLERY_IMG_DIR . 'thumbnail/' . $row['im_thumbnail']);
// and then remove the database entry
$sql = "DELETE FROM tbl_image
WHERE im_id = {$_GET['imgId']} AND im_album_id = {$_GET['album']}";
mysql_query($sql) or die('Delete album failed. ' . mysql_error());
}
}
$imagePerPage = 10;
$album = isset($_GET['album']) ? $_GET['album'] : '';
$pageNumber = isset($_GET['pageNum']) ? $_GET['pageNum'] : 1;
$offset = ($pageNumber - 1) * $imagePerPage;
$serial = $offset + 1;
// get album list
$sql = "SELECT al_id, al_name
FROM tbl_album
ORDER BY al_name";
$result = mysql_query($sql) or die('Error, get album list failed : ' . mysql_error());
$albumList = '';
while ($row = mysql_fetch_assoc($result)) {
$albumList .= '<option value="' . $row['al_id'] . '"' ;
if ($row['al_id'] == $album) {
$albumList .= ' selected';
}
$albumList .= '>' . $row['al_name'] . '</option>';
}
?>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
<tr>
<td align="right">Album :
<select name="cboAlbum" id="cboAlbum" onChange="viewImage(this.value)">
<option value="">-- All Album --</option>
<?php echo $albumList; ?>
</select></td>
</tr></table>
<?php
$sql = "SELECT im_id, im_title, im_thumbnail, DATE_FORMAT(im_date, '%Y-%m-%d') AS im_date
FROM tbl_image ";
if ($album != '') {
$sql .= "WHERE im_album_id = $album ";
}
$sql .= "ORDER BY im_title ";
$result = mysql_query($sql . "LIMIT $offset, $imagePerPage") or die('Error, list image failed. ' . mysql_error());
?>
<table width="100%" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#FFFFFF" class="table_grey">
<tr>
<th width="30" align="center" bgcolor="#000000"><span class="style1">#</span></th>
<th align="center" bgcolor="#000000"><span class="style1">Image </span></th>
<th width="120" align="center" bgcolor="#000000"> Date</th>
<th width="60" align="center" bgcolor="#000000"> </th>
<th width="60" align="center" bgcolor="#000000"> </th>
</tr>
<?php
if (mysql_num_rows($result) == 0) {
?>
<tr bgcolor="#000000">
<td colspan="5"><span class="style1">No image in this album</span></td>
</tr>
<?php
} else {
while ($row = mysql_fetch_assoc($result)) {
extract($row);
?>
<tr bgcolor="#FFFFFF">
<td width="30" align="center" bgcolor="#000000"><span class="style1"><?php echo $serial++; ?></span></td>
<td align="center" bgcolor="#000000"><a href="?page=image-detail&imgId=<?php echo $im_id; ?>" class="style1"><img src="../viewImage.php?type=glthumbnail&name=<?php echo $row['im_thumbnail']; ?>" border="0"><br>
<?php echo $row['im_title']; ?></a></td>
<td width="120" align="center" bgcolor="#000000"><?php echo $im_date; ?></td>
<td width="60" align="center" bgcolor="#000000"><a href="?page=modify-image&imgId=<?php echo $im_id; ?>">Modify</a></td>
<td width="60" align="center" bgcolor="#000000"><a href="javascript:deleteImage(<?php echo "'$album', $im_id"; ?>);">Delete</a></td>
</tr>
<?php
} // end while
}
?>
<tr bgcolor="#000000">
<td colspan="5" align="center"> <span class="style1">
<?php
$result = mysql_query($sql);
$totalResults = mysql_num_rows($result);
echo getPagingLink($totalResults, $pageNumber, $imagePerPage, "page=list-image&album=$album");
?>
</span></td>
</tr>
<tr bgcolor="#000000">
<td colspan="5" align="right"><input name="btnAdd" type="button" onclick="window.location.href='index.php?page=add-image&album=<?php echo $album; ?>';" value="Add Image" /></td>
</tr>
</table>
veiwImage.php
Code: Select all
<?php
/*
All images in the gallery can be stored outside the
webroot directory to prevent direct linking.
To display the image we must provide the image type
and the image name
*/
if (!isset($_GET['type']) || !isset($_GET['name'])) {
exit;
}
// type can be album or gallery image
$type = $_GET['type'];
// this is the image name
$name = $_GET['name'];
include 'library/config.php';
if ($type == 'album') {
$filePath = ALBUM_IMG_DIR . $name;
} else if ($type == 'glimage') {
$filePath = GALLERY_IMG_DIR . $name;
} else if ($type == 'glthumbnail') {
$filePath = GALLERY_IMG_DIR . 'thumbnail/' . $name;
} else {
// invalid image type
exit;
}
// the the browser know the file size
header("Content-length: " . filesize($filePath));
// the image content type is image/[file extension]
header("Content-type: image/" . substr($name, strpos($name, '.') + 1));
// read the image file from the server and send it to the browser
readfile($filePath);
?>
config.php
Code: Select all
<?php
// db properties
$dbhost = '******';
$dbuser = '******';
$dbpass = '****';
$dbname = *******;
// an album can have an image used as thumbnail
// we save the album image here
define('ALBUM_IMG_DIR', '../images/album/');
// all images inside an album are stored here
define('GALLERY_IMG_DIR', '../images/gallery/');
// When we upload an image the thumbnail is created on the fly
// here we set the thumbnail width in pixel. The height will
// be adjusted proportionally
define('THUMBNAIL_WIDTH', 100);
// make a connection to mysql here
$conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("I cannot connect to the database because: " . mysql_error());
mysql_select_db ($dbname) or die ("I cannot select the database '$dbname' because: " . mysql_error());
?>