Kategori
PHP

Membuat Thumbnail-Version dari Gambar dengan PHP

Studi Kasus : Membuat thumbnail dari gambar dengan PHP GD Library
Kebutuhan : Webserver Packages, already installed. Dan pastikan versi PHP anda mensupport Image GD Library (versi 1-8 keatas)
Ikuti langkah-langkah dibawah.

Step 1 : Persiapkan Folder Kerja

  1. Buat folder dengan nama tutorphp dalam document root anda
  2. Siapkan sample JPG image dalam folder ini. Untuk tutorial ini saya menggunakan image dibawah ini (catat : anda bisa menggunakan image apapun, asalkan berekstensi JPG). Jika anda ingin menggunakan image ini, silahkan klik kanan pada image dan pilih save as
  3. Rename gambar anda dengan nama myPic.jpg (catat : rename ini tidak berarti apapun, hanya untuk memudahkan anda mengikuti tutorial ini πŸ˜› )

Step 2 : Membuat script utama untuk resize image ke dalam thumbnail

  1. Ketikkan script berikut,
    [sourcecode language=”php”]
    <?php
    $image = ‘myPic.jpg’; //default image, change here if you want to use another image

    //get the image size and image info
    list($width_orig, $height_orig, $image_type) = getimagesize($image);

    if($image_type !== 2) { // 2 is for JPEG Image
    echo ‘Image is not JPEG Image!’;
    }
    else {
    $thumbname = ‘thumbnail_’.$image; //default name for thumbnail version of image

    // setting the height for the width 75px (75px is default width for the thumbnail). this is for maintain the ratio
    $height_tb = (int) ((75 / $width_orig) * $height_orig);

    //Create a new true color image
    $image_p = imagecreatetruecolor(75, $height_tb);

    //Create a new JPEG image from file or URL
    $image = imageCreateFromJpeg($image); //

    //Copy and resize part of an image with resampling
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, 75, $height_tb, $width_orig, $height_orig);

    //upload image to folder
    if(!is_writeable(dirname($thumbname)))
    {
    echo ‘Unable to Upload image to ‘ . dirname($thumbname);
    }
    else
    {
    //output image to browser or file, the parameter is imageJPEG(resource image, name of the image, quality)
    imageJpeg($image_p, $thumbname, 100);
    }
    }
    ?>
    <center><h1>Create Thumbnail Image</h1>
    <table border=’1′ cellpadding=’5′ cellspacing=’5′>
    <tr align=’center’> <td>Original</td> <td>Thumbnail</td> </tr>
    <tr> <td><img src="myPic.jpg" alt="image" /></td> <td><img src="<?php echo $thumbname;?>" alt="thumbnail" /></td></tr>
    </table>
    <center>
    [/sourcecode]

  2. simpan dengan nama imagetb.php, dan simpan dalam folder tutorphp
  3. Penjelasan : Dapat dilihat di script langsung (script berwarna hijau), Okay

Step 3 : Testing Code

  1. Pergi ke http://localhost/tutorphp/imagetb.php
  2. Anda akan melihat image anda tadi (original) beserta versi thumbnailnya πŸ˜€ just like the picture below..
  3. Cek di folder tutor.php. Anda akan menemukan file image thumbnail_myPic.jpg yang merupakan versi thumbnail dari image anda.

πŸ˜€

Kategori
PHP

Simple Guest Book with PHP & Mysql

Case Study : Create simple guest book with PHP Mysql
Requirements : Webserver Packages, already installed.

Ok, lets just practices.

Step 1 : Prepare the Database

  1. Create database named db_tutorial
  2. Prepare tabel named tb_guestbook, with structure like below.
  3. Done!

Step 2 : Prepare the Work Folder

  1. Create folder named tutorphp in your document root
  2. Save all the files in this tutorial in this folder.

Step 3 : Create script to connect to DB

  1. Type the following script,
    [sourcecode language=”php”]<br />
    &lt;?php<br />
    $host = &quot;localhost&quot;;<br />
    $user = &quot;root&quot;;//adjust according to your mysql setting<br />
    $pass = &quot;&quot;; //adjust according to your mysql setting, i use no password here<br />
    $dbName = &quot;db_tutorial&quot;;<br />
    mysql_connect($host, $user, $pass);<br />
    mysql_select_db($dbName)<br />
    or die (&quot;Connect Failed !! : &quot;.mysql_error());<br />
    ?&gt;<br />
    [/sourcecode]
  2. Save with the name connect.php

Step 4 : Create the GuestBook Form

  1. Type the following script,
    [sourcecode language=”php”]<br />
    &lt;h1&gt;Guestbook&lt;/h1&gt;<br />
    &lt;form method=&quot;post&quot; action=&quot;savegb.php&quot;&gt;<br />
    &lt;table&gt;<br />
    &lt;tr&gt;&lt;td&gt;Your Name&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;<br />
    &lt;tr&gt;&lt;td&gt;Your Email&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;<br />
    &lt;tr&gt;&lt;td&gt;Your Comment&lt;/td&gt;&lt;td&gt;&lt;textarea name=&quot;comment&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;<br />
    &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;<br />
    &lt;/table&gt;<br />
    &lt;/form&gt;</p>
    <p>[/sourcecode]
  2. save with the name formguestbook.php

Step 5 : Create a Processing Script

  1. Type the following script,
    [sourcecode language=”php”]<br />
    &lt;?php<br />
    include ‘connect.php’;</p>
    <p>$name = $_POST[‘name’]; //get the name value from form<br />
    $email = $_POST[‘email’]; //get the email value from form<br />
    $comment = $_POST[‘comment’]; //get the comment value from form</p>
    <p>//query to save to database<br />
    $q1 = &quot;INSERT into tb_guestbook value (”,’$name’,’$email’,’$comment’)&quot;;<br />
    $result1 = mysql_query($q1);</p>
    <p>//query to get data from database<br />
    $q2 = ‘SELECT * FROM tb_guestbook order by id desc’;<br />
    $result2 = mysql_query($q2);</p>
    <p>//show the data from database<br />
    while ($record = mysql_fetch_array($result2)) {<br />
    echo &quot;&lt;table&gt;&quot;;<br />
    echo &quot;&lt;tr&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&quot;.$record[‘name’].&quot;&lt;/td&gt;&lt;/tr&gt;&quot;;<br />
    echo &quot;&lt;tr&gt;&lt;td&gt;Email&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&quot;.$record[‘email’].&quot;&lt;/td&gt;&lt;/tr&gt;&quot;;<br />
    echo &quot;&lt;tr&gt;&lt;td&gt;Comment&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&quot;.$record[‘comment’].&quot;&lt;/td&gt;&lt;/tr&gt;&quot;;<br />
    echo &quot;&lt;/table&gt;&quot;;<br />
    echo &quot;&lt;br/&gt;&quot;;<br />
    }<br />
    ?&gt;<br />
    [/sourcecode]
  2. Save with the name savegb.php
  3. For the explanation, see script’s comment πŸ˜€

Step 6 : Testing Code

  1. Go to http://localhost/tutorphp/formguestbook.php. You will see the form like below. Fill the form (the example is like the picture below).
  2. Click save and you will see the result.

OK. Haaaaaaaapppy Coding! πŸ˜€

Kategori
PHP

GuestBook Sederhana dengan PHP & Mysql

Studi Kasus : Membuat guestbook sederhana dengan PHP Mysql
Kebutuhan : Webserver Packages, already installed.

Ok, langsung praktik saja.

Step 1 : Persiapkan Database

  1. Buat database dengan nama db_tutorial
  2. Siapkan tabel dengan nama tb_guestbook, dengan struktur tabel seperti gambar dibawah ini.
  3. Done!

Step 2 : Persiapkan Folder Kerja

  1. Buat folder dengan nama tutorphp dalam document root anda
  2. Simpan semua file dalam tutorial ini dalam folder tersebut.

Step 3 : Membuat script koneksi ke Database

  1. Ketikkan script berikut,
    [sourcecode language=”php”]
    <?php
    $host = "localhost";
    $user = "root";//adjust according to your mysql setting
    $pass = ""; //adjust according to your mysql setting, i use no password here
    $dbName = "db_tutorial";
    mysql_connect($host, $user, $pass);
    mysql_select_db($dbName)
    or die ("Connect Failed !! : ".mysql_error());
    ?>
    [/sourcecode]
  2. simpan dengan nama connect.php

Step 4 : Membuat form guestbook

  1. Ketikkan script berikut,
    [sourcecode language=”php”]
    <h1>Guestbook</h1>
    <form method="post" action="savegb.php">
    <table>
    <tr><td>Your Name</td><td></td></tr>
    <tr><td>Your Email</td><td></td></tr>
    <tr><td>Your Comment</td><td><textarea name="comment"></textarea></td></tr>
    <tr><td></td><td></td></tr>
    </table>
    </form>

    [/sourcecode]

  2. simpan dengan nama formguestbook.php

Step 5 : Membuat script pemrosesan dan menampilkan guestbook

  1. Ketikkan script berikut,
    [sourcecode language=”php”]
    <?php
    include ‘connect.php’;

    $name = $_POST[‘name’]; //get the name value from form
    $email = $_POST[‘email’]; //get the email value from form
    $comment = $_POST[‘comment’]; //get the comment value from form

    //query to save to database
    $q1 = "INSERT into tb_guestbook value (”,’$name’,’$email’,’$comment’)";
    $result1 = mysql_query($q1);

    //query to get data from database
    $q2 = ‘SELECT * FROM tb_guestbook order by id desc’;
    $result2 = mysql_query($q2);

    //show the data from database
    while ($record = mysql_fetch_array($result2)) {
    echo "<table>";
    echo "<tr><td>Name</td><td>:</td><td>".$record[‘name’]."</td></tr>";
    echo "<tr><td>Email</td><td>:</td><td>".$record[‘email’]."</td></tr>";
    echo "<tr><td>Comment</td><td>:</td><td>".$record[‘comment’]."</td></tr>";
    echo "</table>";
    echo "<br/>";
    }
    ?>
    [/sourcecode]

  2. simpan dengan nama savegb.php
  3. untuk penjelasan script, lihat komentar pada script πŸ˜€

Step 6 : Testing Code

  1. Pergi ke http://localhost/tutorphp/formguestbook.php. Anda akan melihat form seperti dibawah. Isikan guestbook tersebut (misal seperti pada gambar dibawah)
  2. Klik tombol save dan anda akan melihat hasilnya

OK. Haaaaaaaapppy Coding! πŸ˜€

Kategori
PHP

Get the Other Site’s Feeds with SimplePie RSS Reader

Case Study : Get the other’s site feed with RSS Reader SimplePie, show it, and save it to database.
Requirements : SimplePie library, download here. Webserver Packages, already installed.

RSS (Really Simple Syndication) is a xml based format that used to sharing and delivering web content that usually updated regularly. While the term “output” refers to the outputs of RSS which can be read with RSS Feed Reader. SimplePie is a RSS Feed Reader/Parser that quite famous (and my favorite of course), the way RSS Feed Parser working is to read a XML format contained in the RSS Feed which we set ourselves.

Okay, lets give it a try.

Step 1 : Prepare the Database

  1. Create a new database named db_tutorial
  2. Create table tb_rss, with structure like the picture below.
    Table Structure
  3. Done with the database!

Step 2 : Prepare Working Folder

  1. Create a new folder named rss in your document root
  2. Create new folder named cache in the folder rss (…/rss/cache)
  3. Copy file SimplePie.inc (on simplepie zip file) in to folder rss.

Step 3 : Create a Connection to Database

  1. Create a script to connect to database, type the following script,
    <?php
    //file name : connect.php
    //author : littleflow3r
    $host = "localhost";
    $user = "root"; //sesuaikan dengan setting mysql
    $pass = ""; //
    sesuaikan dengan setting mysql
    $dbName = "db_tutorial";
    mysql_connect($host, $user, $pass);
    mysql_select_db($dbName)
    or die ("Connect Failed !! : ".mysql_error());
    ?>
  2. Save in the folder rss with name connect.php

Step 4 : Inisialisasi SimplePie

  1. Type the following script,
    <?php
    //file name : initRSS.php
    //author : littleflow3r
    require_once 'simplepie.inc';
    //initialize simplePie
    $feed = new SimplePie('http://localhost/websmsmasking/feed/rss');
    $feed->set_cache_location('../rss/cache/');
    $feed->set_feed_url('http://localhost/websmsmasking/feed/rss');
    $feed->init();
    $feed->handle_content_type();
    ?>
  2. save in the folder rss and named it initRSS.php
  3. Explanation : The way of SimplePie RSS Parser working is to read the XML format contained adalah dengan membaca format XML contained in the RSS Feed. The Code above is used to initializes SimplePie, by entering the address of our rss [baris 06 dan baris 08]. For example, i use the sample rss address is localhost/websmsmasking/feed/rss –> feed from my local application. You can change this to address that you want, but remember that to gets the rss feed from online sites, you have to be connected to internet, too (this is because simplepie will directly access to that sites.)

Step 5 : Show the Feed

  1. Type the following script,
    <?php
    //file name : rss.php
    //author : littleflow3r
    include 'initRSS.php';
    include 'connect.php';
    //get the feed and show it
    echo "<h1> RSS News Update </h1>";
    foreach ($feed->get_items(0,4) as $item):
    $permalink = $item->get_permalink();
    $title = $item->get_title();
    $desc = $item->get_description();
    echo '<a href="'.$permalink.' ">'; echo $title; echo '</a>';
    echo "<br>";
    echo $desc;
    echo "<br>"; echo "<br>";
    //insert to database
    $q = "INSERT into tb_rss (link, title, description) VALUES('$permalink','$title','$desc')";
    $result = mysql_query($q);
    endforeach;
    ?>
  2. Save in the folder rss, named it rss.php
  3. Explanation: Baris 08 show looping with foreach according to the number of feed obtained from the address of the set RSS’s address, by the get_items(0,4)function, the intention is to take 4 feed items starting from the 0 record.
    Baris 09 save the permalink from each itemsin to variabel $permalink
    Baris 10 get the feed title by the get_title function and save it to $title.
    Baris 11 get the feed description with the get_desc function and save it to $desc.

Step 6 : Testing Code

  1. Go to brwoser, run http://localhost/rss/rss.php
  2. You will see the feed from your rss’s address like image below.
    Result
  3. Check the database, see that tb_rss already filled with rss content from your rss’s address.
    Tb_RSS

Okay, Done. Happy Trying! Happy Coding πŸ™‚

Kategori
WordPress

from WordPress.Com, to WordPress.Org

WordPress.ORG

WordPress.COM

Actually, what’s the difference between blogging with both the above facilities? Please googling if you want to know the definitions of both terms are complete, perhaps Wikipedia will explain it in detail, hahaha. I myself have never googling about the difference the two. According to my understanding, to summarize:

WordPress.COM –> must be ONLINE. Get a free domain with the suffix wordpress.com. For example, www.sapijantan.wordpress.com

WordPress.ORG –> a CMS (like Joomla, Drupal, etc.) that you download, and install on your own. After that you have to upload it on a hosting. The last you usually have to buy a domain, too.

Why WordPress.Org ?

From sapijantan.wordpress.com, you can switch to sapijantan.com. Cool, right? And remember, still with WordPress. So it can be concluded that WordPress.Org is a service provided by wordpress to use wordpress but with our own hosting and domain name, does not belong to WordPress. What are the benefits? Of course by using WordPress.Org, your website / blog more customizable. And there are many other advantages. Hohohoh.

This is a quote from WordPress.Org,

WordPress is web software you can use to create a beautiful website or blog. We like to say that WordPress is both free and priceless at the same time.

Okay, let’s start install it.

Case Study: Installing CMS Wordpress at Localhost

Requirements :

  1. Webserver+PHP+Mysql Package, because we will try to install wordpress on our localhost. You can get it at AppServ or EasyPHP or the others.
  2. CMS WordPress, download here.

Practice 1 : Setting Up the Database

  1. Create a database named wordpress by using phpmyadmin atau mysql command prompt.

    Membuat DB dengan phpmyadmin
    membuat DB dengan phpmyadmin
  2. Leave it blank, you did not need to make a table or etc.

Practice 2 : Installing WordPress

  1. Extract the zip file downloaded from WordPress.Org into your document root.
  2. Rename the extracted folder name to wordpress (actually you can use another name, but for the need for this lab this time we use the same name, though more easily. Okay okay)
  3. Go to http://localhost/. Click on wordpress folder to starting the installation.

    Index Localhost
  • Installing WordPress
  • The figure below shows the installation step-by-step. Oh oh do not worry, for per-step installation instructions there is a picture in the gallery below. Ok, good luck.



    WordPress Installation Instruction

    1. Click on create configuration file to create a configuration file that will be installed on our wordpress.
    2. It would appear the information that directs you to fill in information about the database. Okay, choose let’s go!
    3. Fill our database setting, fill in as shown Step 3 above. Then submit.
      Database name : wordpress
      Username : Adjust according to your mysql setting. Usually root
      Password : Adjust according to your mysql setting. Why password field empty in the picture above? Thats because i use no password πŸ™‚
      fordatabase host and table prefix let it default
    4. Click on Run the install
    5. Fill out the settings that we will create a website with wordpress. You can fill it with as you like, if confused, you can use the example of my settings. Click install wordpress when you have finished filling out the form.
      Site title : Wiwik’s Personal Page
      Username : adminwiwik
      Password : adminwiw1k (write twice)
      email : wiwik@admin.com
    6. TADAAAAAAA. Success!! You have successfully installed wordpress in localhost. To start login on the site, click login.
    7. Enter your username and password (such as the setting in Step 5). Click login.
    8. You will be redirected to the WordPress dashboard. Up here, you can start posting, set the theme, and others such as your activity on wordpress.com:)
    9. To see the “result”, go to http://localhost/wordpress/
    Step 9

    Hohoho. Now you can play around with WordPress on your local server. If you really want to use it, of course you have to upload them on the hosting. Hosting is usually paid, but some are free. If you want to try, please use the free ones first, such as in byethost or freehostia.

    Okay, happy WordPress-ing! Keep Blogging! πŸ˜€

    Kategori
    PHP

    Load and Save the XML Data to Database with PHP & Mysql

    Case Study : Get the XML data and save it to database (mysql)

    Requirements : Webserver Packages, already installed.

    OKAY, no need for trivial chit-chat. Let’s just practice πŸ˜€

    Step 1 : Prepare the Database

    1. Create database named db_tutorial
    2. Create table named tb_dataxml, the structure is as shown below.

    3. Done!

    Step 2 : Prepare the work folder

    1. Create folder named tutorphp in your document root
    2. Save all the file in this tutorial in this folder.

    Step 3 : Create a connection to db script

    1. Type the following script,

      [sourcecode language=”php”]<br /><br />
      &lt;?php<br /><br />
      $host = &quot;localhost&quot;;<br /><br />
      $user = &quot;root&quot;; //adjust according to your mysql setting<br /><br />
      $pass = &quot;&quot;; //adjust according to your mysql setting<br /><br />
      $dbName = &quot;db_tutorial&quot;;<br /><br />
      mysql_connect($host, $user, $pass);<br /><br />
      mysql_select_db($dbName)<br /><br />
      or die (&quot;Connect Failed !! : &quot;.mysql_error());<br /><br />
      ?&gt;<br /><br />
      [/sourcecode]

    2. save with the name connect.php

    Step 4 : Prepare the Sample XML Date

    1. Type the following script,

      [sourcecode language=”xml”]<br /><br />
      &lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;<br /><br />
      &lt;data&gt;<br /><br />
      &lt;record&gt;<br /><br />
      &lt;title&gt;Time to Go&lt;/title&gt;<br /><br />
      &lt;author&gt;June Sushan&lt;/author&gt;<br /><br />
      &lt;publisher&gt;Gramedia Inc&lt;/publisher&gt;<br /><br />
      &lt;date&gt;<br /><br />
      &lt;month&gt;June&lt;/month&gt;<br /><br />
      &lt;year&gt;1989&lt;/year&gt;<br /><br />
      &lt;/date&gt;<br /><br />
      &lt;/record&gt;</p>
      <p> &lt;record&gt;<br /><br />
      &lt;title&gt;Time to Come&lt;/title&gt;<br /><br />
      &lt;author&gt;Alan Smart&lt;/author&gt;<br /><br />
      &lt;publisher&gt;Elexmedia Inc&lt;/publisher&gt;<br /><br />
      &lt;date&gt;<br /><br />
      &lt;month&gt;April&lt;/month&gt;<br /><br />
      &lt;year&gt;1989&lt;/year&gt;<br /><br />
      &lt;/date&gt;<br /><br />
      &lt;/record&gt;</p>
      <p>&lt;/data&gt;</p>
      <p>[/sourcecode]

    2. save with the name record.xml

    Step 5 : Create script for loads the XML, save it database, and show the XML

    1. Type the following script,

      [sourcecode language=”php”]<br /><br />
      &lt;?php<br /><br />
      include ‘connect.php’;<br /><br />
      if( !$xml = simplexml_load_file(‘record.xml’) ) //using simplexml_load_file function to load xml file<br /><br />
      {<br /><br />
      echo ‘load XML failed ! ‘;<br /><br />
      }<br /><br />
      else<br /><br />
      {<br /><br />
      echo ‘&lt;h1&gt;This is the Data&lt;/h1&gt;’;<br /><br />
      foreach( $xml as $record ) //parse the xml file into object<br /><br />
      {<br /><br />
      $title = $record-&gt;title; //get the childnode title<br /><br />
      $author = $record-&gt;author; //get the child node author<br /><br />
      $publisher = $record-&gt;publisher; //get the child node publisher<br /><br />
      $month = $record-&gt;date-&gt;month; //get the child node month<br /><br />
      $year = $record-&gt;date-&gt;year; //get the child node year</p>
      <p> echo ‘Title : ‘.$title.’&lt;br /&gt;’;<br /><br />
      echo ‘Author : ‘.$author.’&lt;br /&gt;’;<br /><br />
      echo ‘Publisher : ‘.$publisher.’&lt;br /&gt;’;<br /><br />
      echo ‘Month : ‘.$month.’&lt;br /&gt;’;<br /><br />
      echo ‘Year : ‘.$year.’&lt;br /&gt;’;<br /><br />
      echo ‘&lt;br&gt;’;</p>
      <p>//save to database<br /><br />
      $q = &quot;INSERT INTO tb_dataxml VALUES(”,’$title’,’$author’,’$publisher’,’$month $year’)&quot;;<br /><br />
      $result = mysql_query($q);<br /><br />
      }<br /><br />
      if ($result) {<br /><br />
      echo ‘&lt;h2&gt;Success Save to Database &lt;/h2&gt;’;<br /><br />
      }<br /><br />
      else echo ‘&lt;h2&gt;Failed Save to Databaase&lt;/h2&gt;’;<br /><br />
      }<br /><br />
      ?&gt; [/sourcecode]

    2. Save with thename loadxml.php

    Step 6 : Testing Code

    1. Go to http://localhost/tutorphp/loadxml.php. You will see the data from record.xml already parsed and showed like in the picture πŸ˜€

    2. Check the database, make sure that the xml data already saved in the table you’ve created on step 1

    So, this is time to trivial chit-chat Ha Ha πŸ˜€ XML is extensible Markup Language.

    Why XML? XML is the standar format for data communication. Because of this, XML often used on the data communication because the platform independen format πŸ˜€

    Kategori
    WordPress

    dari WordPress.Com, ke WordPress.Org

    WordPress.ORG

    WordPress.COM

    Sebenarnya, apa bedanya blogging dengan kedua fasilitas diatas? Silakan googling kalau ingin mengetahui definisi kedua istilah tersebut secara lengkap, mungkin Wikipedia akan menjelaskannya dengan rinci, hahaha. Saya sendiri tidak pernah googling tentang perbedaan keduanya. Menurut pengertian saya, ringkasnya :

    WordPress.COM –> harus ONLINE. Dapat domain gratis dengan akhiran wordpress.com. Contohnya, www.sapijantan.wordpress.com

    WordPress.ORG –> sebuah CMS (seperti Joomla, Drupal, dll) yang anda download, kemudian anda install sendiri. Setelah itu anda harus meng-upload nya pada sebuah hosting. Domain juga anda biasanya harus membelinya.

    Kenapa WordPress.Org ?

    Dari sapijantan.wordpress.com, anda bisa beralih ke sapijantan.com. Keren, bukan? Dan ingat, tetap menggunakan WordPress. Jadi dapat disimpulkan bahwa WordPress.Org merupakan layanan yang diberikan wordpress untuk menggunakan wordpress namun dengan hosting dan domain kita sendiri, bukan milik WordPress. Apa keuntungannya? Tentu saja dengan menggunakan WordPress.Org website/blog yang anda buat bisa lebih di customizable. Dan masih banyak keuntungan lain. Hohohoh.

    Ini adalah kutipan dari WordPress.Org,

    WordPress is web software you can use to create a beautiful website or blog. We like to say that WordPress is both free and priceless at theΒ sameΒ time.

    Okelah, mari kita mulai instal.

    Studi Kasus : Menginstall CMS Wordpress di Localhost

    Kebutuhan :

    1. Paket Webserver+PHP_Mysql, karena lagi-lagi kita akan mencoba menginstal wordpress di server lokal/ localhost. Bisa anda dapatkan di AppServ atau EasyPHP atau yang lainnya.
    2. CMS WordPress, download di sini.

    Praktik 1 : Menyiapkan Database

    1. Buat database bernama wordpress dengan menggunakan phpmyadmin atau mysql command prompt.

      Membuat DB dengan phpmyadmin
      membuat DB dengan phpmyadmin
    2. Biarkan database kosong, anda tidak perlu membuat tabel dan sejenisnya.

    Praktik 2 : Instalasi WordPress

    1. Ekstrak file rar hasil download dari WordPress.Org ke dalam document root anda.
    2. Rename folder hasil ekstrak-an dengan nama wordpress (sebenarnya anda bisa menggunakan nama lain, namun untuk kebutuhan praktikum kali ini lebih baik kita gunakan nama yang sama saja, biar lebih gampang. Oke oke )
    3. Buka http://localhost/. Klik pada folder wordpress untuk mulai menjalankan instalasi

      Index Localhost
  • Menginstall WordPress
  • Gambar dibawah menunjukkan cara penginstalan step-by-step nya. Oh oh jangan khawatir, untuk petunjuk instalasi per-step ada dibawah gallery gambar. Ok, selamat mencoba.


    Petunjuk Instalasi WordPress

    1. Klik pada create configuration file untuk membuat file konfigurasi wordpress yang akan kita install.
    2. Akan muncul keterangan yang mengarahkan anda untuk mengisi keterangan mengenai database. Oke, pilih let’s go!
    3. Mengisi setting database kita, isikan seperti pada gambar Step 3 diatas. Kalau sudah, klik submit.Database name : wordpressUsername : sesuaikan dengan setting mysql anda. Biasanya root

      Password : sesuaikan dengan setting mysql anda. Kenapa pada gambar diatas password dikosongi? Karena saya tidak menggunakan password pada mysql saya πŸ™‚

      untuk database host dan table prefix biarkan default

    4. Klik pada Run the install
    5. Mengisi setting website yang akan kita buat dengan wordpress. Anda bisa mengisinya dengan sesuka anda, kalau bingung, anda bisa menggunakan contoh pengaturan saya. Klik install wordpress setelah anda selesai mengisi form. Site title : Wiwik’s Personal PageUsername : adminwiwik

      Password : adminwiw1k (tuliskan dua kali)

      email : wiwik@admin.com

    6. TADAAAAAAA. Sukses !! Anda telah berhasil menginstall wordpress pada localhost. (Yok, makan-makan dulu…). Untuk mulai login, klik login.
    7. Masukkan username dan password (seperti settingan pada Step 5). Klik login.
    8. Anda akan diarahkan ke dashboard wordpress. Sampai disini, anda bisa mulai posting, mengatur tema, dan lain lain seperti kegiatan anda di wordpress.com πŸ™‚
    9. Untuk melihat “hasil”nya, pergi ke http://localhost/wordpress/
    Step 9

    Hohoho. Sekarang anda bisa bermain-main dengan wordpress pada server lokal anda. Jika anda ingin menggunakannya benar-benar, tentu saja anda harus meng-uploadnya di hosting. Hosting biasanya berbayar, namun ada juga yang gratisan. Jika anda ingin mencoba, silakan gunakan yang gratisan terlebih dulu seperti di byethost atau freehostia.

    Oke, happy WordPress-ing! Keep Blogging! πŸ˜€

    Kategori
    PHP

    Load dan Menyimpan Data XML ke Database dengan PHP-Mysql

    Studi Kasus : Mengambil data dari XML dan menyimpannya ke dalam database (mysql)
    Kebutuhan : Webserver Packages, already installed.

    OKAY, no need for trivial chit-chat. Let’s just practice πŸ˜€

    Step 1 : Persiapkan Database

    1. Buat database dengan nama db_tutorial
    2. Siapkan tabel dengan nama tb_dataxml, dengan struktur tabel seperti gambar dibawah ini.
    3. Done!

    Step 2 : Persiapkan Folder Kerja

    1. Buat folder dengan nama tutorphp dalam document root anda
    2. Simpan semua file dalam tutorial ini dalam folder tersebut.

    Step 3 : Membuat script koneksi ke DB

    1. Ketikkan script berikut,
      [sourcecode language=”php”]
      <?php
      $host = "localhost";
      $user = "root"; //adjust according to your mysql setting
      $pass = ""; //adjust according to your mysql setting
      $dbName = "db_tutorial";
      mysql_connect($host, $user, $pass);
      mysql_select_db($dbName)
      or die ("Connect Failed !! : ".mysql_error());
      ?>
      [/sourcecode]
    2. simpan dengan nama connect.php

    Step 4 : Menyiapkan data XML

    1. Ketikkan script berikut,
      [sourcecode language=”xml”]
      <?xml version="1.0" encoding="iso-8859-1"?>
      <data>
      <record>
      <title>Time to Go</title>
      <author>June Sushan</author>
      <publisher>Gramedia Inc</publisher>
      <date>
      <month>June</month>
      <year>1989</year>
      </date>
      </record>

      <record>
      <title>Time to Come</title>
      <author>Alan Smart</author>
      <publisher>Elexmedia Inc</publisher>
      <date>
      <month>April</month>
      <year>1989</year>
      </date>
      </record>

      </data>

      [/sourcecode]

    2. simpan dengan nama record.xml

    Step 5 : Membuat script untuk me-load XML, menyimpan ke database, dan menampilkan XML

    1. Ketikkan script berikut,
      [sourcecode language=”php”]
      <?php
      include ‘connect.php’;
      if( !$xml = simplexml_load_file(‘record.xml’) ) //using simplexml_load_file function to load xml file
      {
      echo ‘load XML failed ! ‘;
      }
      else
      {
      echo ‘<h1>This is the Data</h1>’;
      foreach( $xml as $record ) //parse the xml file into object
      {
      $title = $record->title; //get the childnode title
      $author = $record->author; //get the child node author
      $publisher = $record->publisher; //get the child node publisher
      $month = $record->date->month; //get the child node month
      $year = $record->date->year; //get the child node year

      echo ‘Title : ‘.$title.'<br />’;
      echo ‘Author : ‘.$author.'<br />’;
      echo ‘Publisher : ‘.$publisher.'<br />’;
      echo ‘Month : ‘.$month.'<br />’;
      echo ‘Year : ‘.$year.'<br />’;
      echo ‘<br>’;

      //save to database
      $q = "INSERT INTO tb_dataxml VALUES(”,’$title’,’$author’,’$publisher’,’$month $year’)";
      $result = mysql_query($q);
      }
      if ($result) {
      echo ‘<h2>Success Save to Database </h2>’;
      }
      else echo ‘<h2>Failed Save to Databaase</h2>’;
      }
      ?> [/sourcecode]

    2. simpan dengan nama loadxml.php

    Step 6 : Testing Code

    1. Pergi ke http://localhost/tutorphp/loadxml.php. Anda akan melihat data dari record.xml telah diparsing dan ditampilkan seperti gambar dibawah πŸ˜€
    2. Cek database anda, pastikan bahwa data dari XML telah tersimpan dalam tabel yang telah anda siapkan pada step 1

    So, this is time to trivial chit-chat Ha Ha πŸ˜€ XML adalah extensible Markup Language.
    Why XML? XML adalah format data standar (yang telah disepakati) yang digunakan dalam pertukaran data. Karena ke-global-an XML itulah, XML sering digunakan dalam komunikasi data karena formatnya yang platform independent πŸ˜€

    Kategori
    PHP

    Tutorial Image Uploading, Saving and Showing.

    Case Study : Create a script to image uploading, save image location to database, and show them.
    Requirements : Webserver Packages, already installed.

    Follow all this step,

    Step 1 : Prepare the Database

    1. Create database named db_tutorial
    2. Prepare table named tb_image, see the table’s structure below.
    3. Done with the database!

    Step 2 : Prepare the wcorking folder

    1. Create folder named helloMobile in your document root
    2. Create folder again named image inside helloMobile folder created before. This Folder required for saving the image that have been uploaded.
    3. Save all file in this tutorial in the helloMobile folder.

    Step 3 : Create script connect to DB

    1. Type the following script,
      [sourcecode language=”php”]
      <?php
      $host = "localhost";
      $user = "root";
      $pass = "";
      $dbName = "db_tutorial";
      mysql_connect($host, $user, $pass);
      mysql_select_db($dbName)
      or die ("Connect Failed !! : ".mysql_error());
      ?>
      [/sourcecode]
    2. Save with the name connect.php, and save in the helloMobile folder

    Step 4 : Create the upload image form

    1. Type the following script,
      [sourcecode language=”php”]
      <form name="form" method="post" enctype="multipart/form-data" action="proses.php">
      Image : <input name="picture" type="file" />
      <input type="submit" name="upload" value="Upload" />
      </form>
      [/sourcecode]
    2. Save with the name formupload.php, save in the helloMobile folder

    Step 5 : Create processing script

    1. Ketikkan script berikut,
      [sourcecode language=”php”]
      <?php
      include "connect.php";
      $fileName = $_FILES[‘picture’][‘name’]; //get the file name
      $fileSize = $_FILES[‘picture’][‘size’]; //get the size
      $fileError = $_FILES[‘picture’][‘error’]; //get the error when upload
      if($fileSize > 0 || $fileError == 0){ //check if the file is corrupt or error
      $move = move_uploaded_file($_FILES[‘picture’][‘tmp_name’], ‘E:/DocumentRootYuni/helloMobile/image/’.$fileName); //save image to the folder
      if($move){
      echo "<h3>Success! </h3>";
      $q = "INSERT into tb_image VALUES(”,’$fileName’,’image/$fileName’)"; //insert image property to database
      $result = mysql_query($q);

      $q1 = "SELECT location from tb_image where filename = ‘$fileName’ limit 1 "; //get the image that have been uploaded
      $result = mysql_query($q1);
      while ($data = mysql_fetch_array($result)) {
      $loc = $data[‘location’]; ?>
      <br/>
      <h2> This is the Image : </h2>
      <img src="<?php echo $loc; ?>" /> <!– show the image using img src –>
      <?php
      }
      } else{
      echo "<h3>Failed! </h3>";
      }
      } else {
      echo "Failed to Upload : ".$fileError;
      }
      ?>
      [/sourcecode]

    2. Save with the name prosesupload.php
    3. See the script’s comment for the explanation πŸ˜€

    Step 6 : Testing Code

    1. Go to http://localhost/helloMobile/formupload.php. And you will see the form below,
    2. Try to upload image. Choose a image file with click browse button
    3. Save. So the image will be shown to you πŸ˜€
    Kategori
    PHP

    Tutorial Upload, Menyimpan, dan Menampilkan Gambar dengan PHP dan Mysql

    Studi Kasus : Membuat script untuk menguload image,menyimpan lokasi image ke database dan menampilkannya
    Kebutuhan : Webserver Packages, already installed.

    Ikuti langkah-langkah dibawah.

    Step 1 : Persiapkan Database

    1. Buat database dengan nama db_tutorial
    2. Siapkan tabel dengan nama tb_image, dengan struktur tabel seperti gambar dibawah ini.
    3. Done with the database!

    Step 2 : Persiapkan Folder Kerja

    1. Buat folder dengan nama helloMobile dalam document root anda
    2. Buat lagi folder dengan nama image didalam folder helloMobile yang telah anda buat sebelumnya. Folder image ini adalah folder yang akan digunakan untuk menyimpan gambar hasil upload.
    3. Simpan semua file dalam praktikum ini dalam folder helloMobile tersebut.

    Step 3 : Membuat script koneksi ke DB

    1. Ketikkan script berikut,
      [sourcecode language=”php”]
      <?php
      $host = "localhost";
      $user = "root";
      $pass = "";
      $dbName = "db_tutorial";
      mysql_connect($host, $user, $pass);
      mysql_select_db($dbName)
      or die ("Connect Failed !! : ".mysql_error());
      ?>
      [/sourcecode]
    2. simpan dengan nama connect.php, dan simpan dalam folder helloMobile

    Step 4 : Membuat form upload image

    1. Ketikkan script berikut,
      [sourcecode language=”php”]
      <form name="form" method="post" enctype="multipart/form-data" action="proses.php">
      Image : <input name="picture" type="file" />
      <input type="submit" name="upload" value="Upload" />
      </form>
      [/sourcecode]
    2. simpan dengan nama formupload.php, simpan dalam folder helloMobile

    Step 5 : Membuat script pemrosesan dan menampilkan gambar hasil upload

    1. Ketikkan script berikut,
      [sourcecode language=”php”]
      <?php
      include "connect.php";
      $fileName = $_FILES[‘picture’][‘name’]; //get the file name
      $fileSize = $_FILES[‘picture’][‘size’]; //get the size
      $fileError = $_FILES[‘picture’][‘error’]; //get the error when upload
      if($fileSize > 0 || $fileError == 0){ //check if the file is corrupt or error
      $move = move_uploaded_file($_FILES[‘picture’][‘tmp_name’], ‘E:/DocumentRootYuni/helloMobile/image/’.$fileName); //save image to the folder
      if($move){
      echo "<h3>Success! </h3>";
      $q = "INSERT into tb_image VALUES(”,’$fileName’,’image/$fileName’)"; //insert image property to database
      $result = mysql_query($q);

      $q1 = "SELECT location from tb_image where filename = ‘$fileName’ limit 1 "; //get the image that have been uploaded
      $result = mysql_query($q1);
      while ($data = mysql_fetch_array($result)) {
      $loc = $data[‘location’]; ?>
      <br/>
      <h2> This is the Image : </h2>
      <img src="<?php echo $loc; ?>" /> <!– show the image using img src –>
      <?php
      }
      } else{
      echo "<h3>Failed! </h3>";
      }
      } else {
      echo "Failed to Upload : ".$fileError;
      }
      ?>
      [/sourcecode]

    2. simpan dengan nama proses.php
    3. Untuk penjelasan script, dapat dilihat di komentar script πŸ˜€

    Step 6 : Testing Code

    1. Pergi ke http://localhost/helloMobile/formupload.php. Anda akan melihat form seperti dibawah,
    2. Pilih gambar yang ingin diupload dengan memilih tombol browse
    3. Pilih save. Maka gambar yang telah anda upload akan ditampilkan πŸ˜€