Dec
16th

PHP Image Gallery Part II

Files under MySQL, PHP | Posted by phpcrazy

Database ေဆာက္ၿပီးသြားၿပီ ဆိုရင္ေတာ့ ဖိုင္ေတြ တည္ေဆာက္ရပါမယ္ .. ဖိုင္တည္ေဆာက္ပံုကေတာ့ ေအာက္ကအတိုင္း ျဖစ္ပါတယ္။

image-gallery.png

image folder မွာ ဓာတ္ပံုေတြ သိမ္းဆည္းမွာ ျဖစ္ၿပီး image ေတြရဲ႕ နမူနာပံုေသး(thumbnail)ေတြ ကေတာ့ gallery ေအာက္က subdirectory ထဲမွာ သိမ္းဆည္းမွာ ျဖစ္ပါတယ္။ album, gallery, thumbnail စတဲ့ folder ေတြကို Write Access ေပးထားဖို႔လိုပါတယ္။ Write Access ေပးတယ္ဆိုတာ Linux အတြက္ အဓိက ျဖစ္ပါတယ္။ CHMOD ဆိုတဲ့ command ကို အသံုးျပဳရပါတယ္။ WAMP မွာေတာ့ မလိုပါဘူး။

Configurations


session_start();

// db properties
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'gallery';

// an album can have an image used as thumbnail
// we save the album image here
define('ALBUM_IMG_DIR', 'C:/webroot/gallery/images/album/');

// all images inside an album are stored here
define('GALLERY_IMG_DIR', 'C:/webroot/gallery/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());
?>

အေပၚဖက္က source code ေတြကို ကူးၿပီး config.php ဆိုတဲ့ ဖိုင္ကို တည္ေဆာက္လိုက္ပါ။ ၿပီးရင္ c:\wamp\www\gallery\library\ ထဲမွာ Save ပါ။ ေအာက္က တန္ဖိုးေတြကို ကိုယ့္ program နဲ႔ကိုက္ေအာင္ ျပင္ရပါမယ္။

1. ALBUM_IMG_DIR, GALLERY_IMG_DIR (ဒီေနရာမွာ ကိုယ့္ image ဖိုင္ေတြရွိတဲ့ ေနရာေတြကို ေသေသခ်ာခ်ာ ၫႊန္းေပးဖို႔ လိုပါတယ္။ WAMP မွာဆိုရင္ေတာ့ ေအာက္က အတိုင္းျဖည့္ ေပးလိုက္ပါ။


define('ALBUM_IMG_DIR', 'C:/wamp/www/gallery/images/album/');

define('GALLERY_IMG_DIR', 'C:/wamp/www/gallery/images/gallery/');

ေနာက္တစ္ခ်က္အေနနဲ႔ အခု image gallery က GD Library ဆိုတာကို အသံုးျပဳပါတယ္။ ဒီလိုအသံုးျပဳမယ္ဆိုေတာ့ ကိုယ့္စက္မွာ GD Library အလုပ္လုပ္သလား ဆိုတာကို ၾကည့္ဖို႔ လိုပါတယ္။ ေအာက္မွာ ေပးထားတဲ့ source code ကို ကူးၿပီး php ဖိုင္အေနနဲ႔ c:\wamp\www ထဲမွာ testgd.php လို႔ေပးၿပီး save ပါ။ ၿပီးရင္ Browser မွာ http://localhost/gdtest.php ဆိုၿပီး ရိုက္ၾကည့္ပါ၊

 

OK, you already have GD library installed ဆိုတဲ့ စာေလးေပၚလာရင္ေတာ့ အိုေကပါၿပီ။ အကယ္၍ မေပၚလာဘူးဆိုရင္ေတာ့ php.ini မွာ extension=php_gd2.dll ဆိုတာေလးကို ရွာၿပီး ေရွ႕က “;” ေလးကို ျဖဳတ္လိုက္ပါ၊ ၿပီးရင္ apache server ကို restart လုပ္ပါ။

 

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

အပိုင္း (၃) သို႔ ..


3 Responses to “PHP Image Gallery Part II”

  1. By mm on Dec 25, 2007 | Reply

    “ALBUM_IMG_DIR, GALLERY_IMG_DIR (ဒီေနရာမွာ ကိုယ့္ image ဖိုင္ေတြရွိတဲ့ ေနရာေတြကို ေသေသခ်ာခ်ာ ၫႊန္းေပးဖို႔ လိုပါတယ္။ WAMP မွာဆိုရင္ေတာ့ ေအာက္က အတိုင္းျဖည့္ ေပးလိုက္ပါ။

    define(’ALBUM_IMG_DIR’, ‘C:/wamp/www/gallery/images/album/’);

    define(’GALLERY_IMG_DIR’, ‘C:/wamp/www/gallery/images/gallery/’); ”

    Bro, where to fill these source code? I dont know where to find and fill in phpMyAdmin. I’m left out in ur instructions. Can u plz make ur explanation in step by step? thz

  2. By phpcrazy on Dec 25, 2007 | Reply

    config.php ဖိုင္ကို တည္ေဆာက္တဲ့အခါ Dreamweaver မွာ ျဖစ္ျဖစ္ NotePad မွာ ျဖစ္ျဖစ္ ကူးၿပီး တည္ေဆာက္လို႔ ရႏိုင္ပါတယ္။ phpMyAdmin မွာကေတာ့ Database နဲ႔ ပတ္သက္တာေတြကို စီမံခန္႔ခြဲႏိုင္ပါတယ္။ Script ေတြကိုေတာ့ Editor ေတြနဲ႔ တည္ေဆာက္ရပါတယ္ …

    Comment ေပးၿပီး ေမးႏိုင္ပါတယ္…

  3. By zmtun84 on Nov 6, 2008 | Reply

    image ကုိ upload လုပ္လို႔မရဘူးျဖစ္ေနတယ္ အစ္ကိုရ..

    Warning: move_uploaded_file(C:/webroot/gallery/images/gallery/1cbd0435228560a004a7d8e361470106.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\gallery\library\functions.php on line 21

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘C:\wamp\tmp\php3A.tmp’ to ‘C:/webroot/gallery/images/gallery/1cbd0435228560a004a7d8e361470106.jpg’ in C:\wamp\www\gallery\library\functions.php on line 21
    Error uploading file

    အဲ့လိုျပေနလို႔…..ဘာကိုျပင္ရမလဲ မသိဘူး….အၾကံေလးေပးပါဦးဗ်ာ…ေတာင္းဆိုပါတယ္…

Post a Comment