Ok Thanks, here are the codes:
The code below is my code for config. It defines the upload directory and also the database connection:
[PHP]<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connx = "localhost";
$database_connx = "sbdb";
$username_connx = "root";
$password_connx = "sbdbadm1n";
$connx = mysql_pconnect($hostname_connx, $username_connx, $password_connx) or trigger_error(mysql_error(),E_USER_ERROR);
// an album can have an image used as thumbnail
// we save the album image here
define("ALBUM_IMG_DIR", "/var/www/html/domains/supportbridges.org/documentroot/sbi/images/album/
");
// all images inside an album are stored here
define("GALLERY_IMG_DIR", "/var/www/html/domains/supportbridges.org/documentroot/sbi/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', 40);
// make a connection to mysql here
$connx = mysql_connect ($hostname_connx, $username_connx, $password_connx) or die ("I cannot connect to the database because: " . mysql_error());
mysql_select_db ($database_connx) or die ("I cannot select the database '$dbname' because: " . mysql_error());
?>[/PHP]
Now here is my functions code the handles the thumbnail creation and other stuff.
[PHP]<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connx = "localhost";
$database_connx = "sbdb";
$username_connx = "root";
$password_connx = "sbdbadm1n";
$connx = mysql_pconnect($hostname_connx, $username_connx, $password_connx) or trigger_error(mysql_error(),E_USER_ERROR);
// an album can have an image used as thumbnail
// we save the album image here
define("ALBUM_IMG_DIR", "/Inetpub/wwwroot/projects/support/images/album/");
// all images inside an album are stored here
define("GALLERY_IMG_DIR", "/Inetpub/wwwroot/projects/support/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', 40);
// make a connection to mysql here
$connx = mysql_connect ($hostname_connx, $username_connx, $password_connx) or die ("I cannot connect to the database because: " . mysql_error());
mysql_select_db ($database_connx) or die ("I cannot select the database '$dbname' because: " . mysql_error());
?>[/PHP]
Now here is my add album code the adds new album to the fileserver and database.
[PHP]<?php
require_once '../library/config.php';
require_once '../library/functions.php';
if(isset($_POST['txtName']))
{
$albumName = $_POST['txtName'];
$albumDesc = $_POST['mtxDesc'];
$imgName = $_FILES['fleImage']['name'];
$tmpName = $_FILES['fleImage']['tmp_name'];
// we need to rename the image name just to avoid
// duplicate file names
// first get the file extension
$ext = strrchr($imgName, ".");
// then create a new random name
$newName = md5(rand() * time()) . $ext;
// the album image will be saved here
$imgPath = ALBUM_IMG_DIR . $newName;
// resize all album image
$result = createThumbnail($tmpName, $imgPath, THUMBNAIL_WIDTH);
if (!$result) {
echo "Error uploading file";
exit;
}
if (!get_magic_quotes_gpc()) {
$albumName = addslashes($albumName);
$albumDesc = addslashes($albumDesc);
}
$query = "INSERT INTO tbl_album (al_name, al_description, al_image, al_date)
VALUES ('$albumName', '$albumDesc', '$newName', NOW())";
mysql_query($query) or die('Error, add album failed : ' . mysql_error());
// the album is saved, go to the album list
echo "<script>window.location.href='index.php?page= list-album';</script>";
exit;
}
?>
<form action="" method="post" enctype="multipart/form-data" name="frmAlbum" id="frmAlbum">
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="table_grey">
<tr>
<th width="150">Album Name</th>
<td width="80" bgcolor="#FFFFFF"> <input name="txtName" type="text" id="txtName"></td>
</tr>
<tr>
<th width="150">Description</th>
<td bgcolor="#FFFFFF"> <textarea name="mtxDesc" cols="50" rows="4" id="mtxDesc"></textarea>
</td>
</tr>
<tr>
<th width="150">Image</th>
<td bgcolor="#FFFFFF"> <input name="fleImage" type="file" class="box" id="fleImage"></td>
</tr>
<tr>
<td width="150" bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"> <input name="btnAdd" type="submit" id="btnAdd" value="Add Album">
<input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.history.back();"></td>
</tr>
</table>
</form>
[/PHP]
Now here is the page it ought to link to, the list-album page.
[PHP]<?php
$albumPerPage = 10;
$pageNumber = isset($_GET['pageNum']) ? $_GET['pageNum'] : 1;
$offset = ($pageNumber - 1) * $albumPerPage;
$serial = $offset + 1;
$sql = "SELECT al_id, al_name, al_image, COUNT(im_album_id) AS al_numimage
FROM tbl_album al LEFT JOIN tbl_image im ON al.al_id = im.im_album_id
GROUP by al_id
ORDER BY al_name ";
$result = mysql_query($sql . "LIMIT $offset, $albumPerPage") or die('Error, list album failed. ' . mysql_error());
?>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="table_grey">
<tr>
<th width="30" align="center">#</th>
<th align="center">Album Name</th>
<th width="120" align="center"> Images</th>
<th width="60" align="center"> </th>
<th width="60" align="center"> </th>
</tr>
<?php
if (mysql_num_rows($result) == 0) {
?>
<tr bgcolor="#FFFFFF">
<td colspan="5">No album yet</td>
</tr>
<?php
} else {
$serial = $offset + 1;
while ($row = mysql_fetch_assoc($result)) {
extract($row);
$al_numimage = "<a href=\"?page=list-image&album=$al_id\">$al_numimage</a>";
?>
<tr bgcolor="#FFFFFF">
<td width="30" align="center"><?php echo $serial++; ?></td>
<td align="center"><a href="?page=album-detail&alId=<?php echo $al_id; ?>"><img src="../viewImage.php?type=album&name=<?php echo $row['al_image']; ?>" border="0" /><br />
</a><a href="?page=album-detail&alId=<?php echo $al_id; ?>"><?php echo $al_name; ?></a></td>
<td width="120" align="center"><?php echo $al_numimage; ?></td>
<td width="60" align="center"><a href="?page=modify-album&alId=<?php echo $al_id; ?>">Modify</a></td>
<td width="60" align="center"><a href="javascript:deleteAlbum(<?php echo $al_id; ?>);">Delete</a></td>
</tr>
<?php
} // end while
}
?>
<tr bgcolor="#FFFFFF">
<td colspan="5" align="center"><?php
$result = mysql_query($sql);
$totalResults = mysql_num_rows($result);
echo getPagingLink($totalResults, $pageNumber, $albumPerPage, "page=list-album");
?> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="5" align="right"><input type="button" name="btnAdd" value="Add Album" onclick="window.location.href='index.php?page=add-album';" /></td>
</tr>
</table>
[/PHP]
Please help, thanks.