Jan
3rd
Files under PHP |
Posted by phpcrazy
ဒီတစ္ခါေတာ့ ကိုယ့္စက္ထဲမွာ စမ္းႏိုင္ဖို႔ Source file ကိုပါတစ္ခါတည္း ေဒါင္းႏိုင္ပါတယ္ခင္ဗ်ာ …
PHP Image Gallery တစ္ခုကို တည္ေဆာက္တဲ့ အပိုင္းက မနည္းပါဘူး။ ဒီလို တစ္ပိုင္းျခင္းစီေရးသြားၿပီးရင္ အားလံုးစုၿပီး PDF အေနနဲ႔ တင္ေပးပါ့မယ္။ ေလာေလာဆယ္ေတာ့ တစ္ပိုင္းျခင္းဆီပဲ ဖတ္ေပးၾကပါလို႔ ေတာင္းပန္ခ်င္ပါတယ္။ Admin Panel ကိုၾကည့္လိုက္ရင္ Add Album ဆိုတဲ့ အပိုင္းကို ေတြ႔ရပါမယ္။ အဲဒီအပိုင္းအတြက္ source code ကေတာ့ ေအာက္မွာ ေဖာ္ျပေပးထား ပါတယ္။ အဲဒီ Source Code ေတြကို ကူးၿပီး add-albums.php ဆိုၿပီး admin directory ထဲမွာ Save လိုက္ပါ။
<?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>
ေအာက္မွာ ျပထားတဲ့ ပံုကေတာ့ Admin Panel ရဲ႕ ပံုစံျဖစ္ပါတယ္။

အပိုင္း(၅) သို႔ …
By zmtun84 on Nov 6, 2008 | Reply
အပိုင္း ၅ ကိုဆက္ တင္ေပးပါဦး လို႔ေတာင္းဆိုခ်င္ပါတယ္ခင္ဗ်ာ……..ေက်းဇူးအထူးတင္ပါတယ္…