Rifky Apriadi

July 17, 2008

pupopwindow

Filed under: PHP

bagaimana cara membuka form dengan window baru? nih sourcenya, pake javascript. duh udah sore nih…mudah-mudahan ini bisa bermanfaat ya

<script language="javascript">
function PopupWindow(strURL,intHeight,intWidth)
{
var newWindow;
var intTop= (screen.height - intHeight) / 2;
var intLeft= (screen.width - intWidth) / 2;
var props = ’scrollBars = yes, resizable = yes, toolbar = no, menubar = no, location = no, directories = no,width=’+intWidth+’,height=’+intHeight+’,left=’+intLeft+’,top=’+intTop+'’;
self.name = "<%=strRandom%>"
newWindow = window.open(strURL, "Popup", props);
}
</script>
<script language="javascript">
function PopupWindowRpt(strURL,intHeight,intWidth)
{
var newWindow;
var intTop= (screen.height - intHeight) / 2;
var intLeft= (screen.width - intWidth) / 2;
var props = ’scrollBars = yes, resizable = yes, toolbar = no, menubar = yes, location = no, directories = no, width=’+intWidth+’,height=’+intHeight+’,left=’+intLeft+’,top=’+intTop+'’;
self.name = "<%=strRandom%>"
newWindow = window.open(strURL, "Popup", props);
}
</script>

trus cara manggilnya? nih :

 <tr valign="center">
            <td width="50%" align="left" style="border-top: 0px solid #000000"><font face="Arial Narrow" size="3" color="#000000">
              <input type="button" name="tombol" value="buka" onClick="PopupWindow(’uploadoc.php?A=I’,131,494);">
            </font>
            </td>

dah ah, waktunya sholat ashar an pulang lagi…. emoticon

download file word

Filed under: PHP

kemarin aku sudah dapat untuk meng-uploat file doc, sekarang gimana cara client mengambil atau melihat file tersebut? nah ini dia lagi-lagi atas bantuan bapak google! emoticon nih sourcenya :

<?php
$strid = $_GET[’id’];
//echo $strid;
//die();
$fpath = "image/$strid";
header("Content-type: application/msword");
//header("Content-type: text/tab-separated-values");
header("Content-Length: ".filesize($fpath));
header("Content-Disposition: filename=".basename($fpath));
readfile($fpath);
exit;

?>

July 16, 2008

how to upload word(doc) with PHP

Filed under: PHP

post sebelumnya udah bisa upload file, tapi itu cuma bisa upload image aja! gimana kalau ada file doc yang mau d upload? tanya lagi sama paman google, an paman google yg baik hati mengantarkan aku sehingga dapat source ini :

<?php
      if(isset($_POST[’submit’])){
      $numfilesuploaded = $_POST[’numuploads’];
      $count = 1;
 
          while ($count <= $numfilesuploaded)
          {
                  $conname = “new_file”.$count;

                  $filetype = $_FILES[$conname][’type’];
                
                  $filename = $_FILES[$conname][’name’];
                  if ($filename != ‘’)
                  {
                    if ($filetype == “application/msword” || $filetype==”application/vnd.openxmlformats-officedocument.wordprocessingml.document”)
                    {
                        $maxfilesize = $_POST[’maxsize’];
                        $filesize = $_FILES[$conname][’size’];
                        if($filesize <= $maxfilesize )
                        {
                              $randomdigit = rand(0000,9999);
                            
                              $newfilename = $randomdigit.$filename;
                              $source = $_FILES[$conname][’tmp_name’];
                              $target = “document/”.$newfilename;
                              move_uploaded_file($source, $target);
                              echo $count.” File uploaded | “;
                     
                       
                        }
                        else
                        {
                            echo $count.” File is too big! 10MB limit! |”;
                       
                        }
                    }
                    else
                    {
                        echo ” The file is not a supported type |”;
      echo $filetype;
                    }
                  }
          $count = $count + 1;
          }
     
      }
?>
<?php
    $numuploads = 1;
    $count = 1;
?>
<form action=”<?php echo $_server[’php-self’];  ?>” method=”post” enctype=”multipart/form-data” id=”something” class=”uniForm”>
<?php
      while ($count <= $numuploads)
      {

?>
      <input name=”new_file<?php echo $count; ?>” id=”new_file<?php echo $count; ?>” size=”30″ type=”file” class=”fileUpload” />
      <?php
            $count = $count + 1;
      }
?>
      <input type = “hidden” name=”maxsize” value = “10240000″>
       <input type = “hidden” name=”numuploads” value = “<?php echo $numuploads; ?>”>
      <br>
      <button name=”submit” type=”submit” class=”submitButton”>Upload Files</button>

</form>

ya, mudah-mudahan bisa bermanfaat untuk yang membutuhkannya!

July 11, 2008

expot mysql to excel

Filed under: PHP

kemaren lg nyari cara import dari excel ke mysql.. cos banyak data maual dari excel mau d conversi k mysql nh! tapi dapetnya malah dari mysql k excel.. nih sourcenya, sapa tau berguna :

<?

// Connect database.
mysql_connect("localhost","root","");
mysql_select_db("dbkar");

// Get data records from table.
$result=mysql_query("select * from tbkar");

// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=orderlist.xls ");
header("Content-Transfer-Encoding: binary ");

xlsBOF();

/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at ‘0′
*/

xlsWriteLabel(0,0,"Karyawan");

// Make column labels. (at line 3)
xlsWriteLabel(2,0,"NIK");
xlsWriteLabel(2,1,"Name");
xlsWriteLabel(2,2,"Telephone");
xlsWriteLabel(2,3,"Address");
$xlsRow = 3;

// Put data records from mysql by while loop.
while($row=mysql_fetch_array($result)){

xlsWriteNumber($xlsRow,0,$row[’nik_kar’]);
xlsWriteLabel($xlsRow,1,$row[’name_kar’]);
xlsWriteLabel($xlsRow,2,$row[’tlp_kar’]);
xlsWriteLabel($xlsRow,3,$row[’adrs_kar’]);

$xlsRow++;
}
xlsEOF();
exit();
?>

July 1, 2008

file upload

Filed under: PHP

nih ada source untuk meng-upload foto ke folder(bukan database) emoticon ini juga berkat googling…  emoticon  semoga bermanfaat, cos u/ gw sendiri bermanfaat bgt emoticon thx nih u/ yg buat!!! maaf gw cuma mau berbagi aja emoticon

 

<?php

/*——————————————————————————
|
|                             PHParadise source code
|
|——————————————————————————-
|
| file:             file upload
| category:         file handling
|
| last modified:    Mon, 20 Jun 2005 16:40:37 GMT
| downloaded:       Wed, 25 Jun 2008 03:40:48 GMT as PHP file
|
| description:
| an easy file upload script. specify the filetypes allowed, the max filesize and
| the directory to upload the files.
|
——————————————————————————*/

 

// specify the directory where the uploaded file should end up
$path = ‘upload/’ ;

// specify the filetypes allowed
$allowed = array(’image/gif’,'image/pjpeg’,'image/jpeg’,'image/png’);

// specify the max filesize in bytes
$max_size = 200000;

if(isset($HTTP_POST_FILES[’userfile’]))
{
 if(is_uploaded_file($HTTP_POST_FILES[’userfile’][’tmp_name’]))
 {
  if($HTTP_POST_FILES[’userfile’][’size’] < $max_size)
  {
   if(in_array($HTTP_POST_FILES[’userfile’][’type’],$allowed))
   {
    if(!file_exists($path . $HTTP_POST_FILES[’userfile’][’name’]))
    {
     if(@rename($HTTP_POST_FILES[’userfile’][’tmp_name’],$path.$HTTP_POST_FILES[’userfile’][’name’]))
     {
      $html_output = ‘Upload sucessful!<br>’;
      $html_output .= ‘File Name: ‘.$HTTP_POST_FILES[’userfile’][’name’].’<br>’;
      $html_output .= ‘File Size: ‘.$HTTP_POST_FILES[’userfile’][’size’].’ bytes<br>’;
      $html_output .= ‘File Type: ‘.$HTTP_POST_FILES[’userfile’][’type’].’<br>’;
      $image = $HTTP_POST_FILES[’userfile’][’name’] ;
     }else{
      $html_output = ‘Upload failed!<br>’;
      if(!is_writeable($path))
      {
       $html_output = ‘The Directory "’.$path.’" must be writeable!<br>’;
      }else{
       $html_output = ‘an unknown error ocurred.<br>’;     
      }
     }
    }else{
     $html_output = ‘The file already exists<br>’;
    }
   }else{
    $html_output = ‘Wrong file type<br>’;
   }
  }else{
   $html_output = ‘The file is too big<br>’;
  }
 }
}else{
 $html_output = ‘<form method="post" enctype="multipart/form-data" action="’.$_SERVER[’PHP_SELF’].’">’;
 $html_output .= ‘<input type="file" name="userfile">’;
 $html_output .= ‘<input type="submit" value="upload">’;
 $html_output .= ‘</form>’;
}

echo ‘<html><head><title>Uploader</title></head><body>’;
echo $html_output;
echo ‘</body></html>’;

?>

March 25, 2008

koneksi database MySQL

Filed under: Java

sebelumnya gw post koneksi dalam PHP, sekarang koneksi menggunakan java. ya, mudah2an aja ada yg bisa memanfaatkan ini!

koneksi.java

import java.sql.*;
import javax.swing.JOptionPane;

public class koneksi
{ public Connection conn;

public koneksi() {}

public Connection openKoneksi()
{
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost/coba?user=root&password=");
            return conn;
        }
        catch(SQLException e)
        {
            e.printStackTrace();
            return null;
        }
        catch(ClassNotFoundException et)
        {
            et.printStackTrace();
            return null;
        }
    }
    public void tutupKoneksi() throws SQLException
    {
    try{
        if(conn!=null)
        System.out.print("Connection Close");

    }
    catch(Exception ex){
        ex.printStackTrace();
    }

    }
}

itu d buat dengan nama kelas koneksi.java, nama database coba, username root dan passwordnya kosong!! dan jangan lupa, kalau untuk java kita harus sertakan pula mysql-connectornya!

ok, mudah2an bermanfaat!! amin…. emoticon 

March 24, 2008

koneksi database MySQL

Filed under: PHP

kemaren waktu ikut test di tanya gimana sih koneksi dari PHP ke MySQL?

mungkin untuk teman-teman yang udah sangat master ini bukan lah apa-apa, tapi ini cuma mau sekedar share aja, apalagi untuk yg baru mau belajar! semoga ini bisa membantu! amain…

nih contohnya!!

koneksi.php

<?php

function open_connection()
{
    $host="localhost";
    $username="root";
    $password="";
    $databasename="coba";
    $link=mysql_connect($host,$username,$password) or die("Database ga bisa terhubung!");
    mysql_select_db($databasename,$link);
    return $link;
}

 

yupz.. itu contoh program biar bisa terkoneksi dengan database yang nama databasenya coba!!!

semoga sukses!! 

March 6, 2008

buat dan baca file XML dengan PHP

Filed under: PHP

ajax, mungkin dengan script ajax di php akan sangat membantu dan lebih cepat! waktu pertama gw mau belajar ajax, eh liat script di bawah ini yg kebetulan juga punyanya ajax! and kebetulan juga gw mau buat program untuk ngambil data di server dari client! kaya’nya ini membantu gw juga, gw buat xml di server an client tinggal baca aja deh (semoga bener pernyataan gw ini) nih codenya

misalnya nama file phpnya create.php. isinya kayak gini:

<?php
   header("Content-type: text/xml");

    $dom = new DomDocument(’1.0′,’UTF-8′);

    $rentals = $dom->appendChild($dom->createElement(’rentals’));

    $description = $rentals->appendChild($dom->createElement(’description’));

    #———-

    $title = $description->appendChild($dom->createElement(’nama’));

    $title->appendChild($dom->createTextNode(’chunkring’));

    #———-

    $title = $description->appendChild($dom->createElement(’alamat’));

    $title->appendChild($dom->createTextNode(’kebon’));

    #———-

    $title = $description->appendChild($dom->createElement(’hobi’));

    $title->appendChild($dom->createTextNode(’makan’));

    #———-

    $title = $description->appendChild($dom->createElement(’status’));

    $title->appendChild($dom->createTextNode(’jawara’));

    #———–

    $title = $description->appendChild($dom->createElement(’asal’));

    $title->appendChild($dom->createTextNode(’betawi’));

    #———–

    $title = $description->appendChild($dom->createElement(’gaji’));

    $title->appendChild($dom->createTextNode(’1000000000 per minggu’));

    #———–

    $dom->formatOutput = true;

    $test = $dom->saveXML();

    $dom->save(’pribadiKu.xml’);

    echo $test;

?>

Script di atas akan menghasilkan satu file xml dengan nama pribadiKu.xml.

Kemudian saya buat file untuk membaca data dari file xml yang tercipta. Misalnya nama filenya

readFromXml.php

<?php

    if(file_exists(’pribadiKu.xml‘)) {

    $data = simplexml_load_file(’pribadiKu.xml‘);

    # raw data in array form

    printr_r($data);

    foreach($data as $key => $dat) {

        foreach($dat as $k => $v) {

            echo ($k);
    echo(” : “);
    echo($v);
           echo (“<br />”);

        }

    }

}

?>

 ya semoga yg baca ini bisa dapet ilmu walau sedikit!!!  emoticon

February 28, 2008

kirim email dengan program java

Filed under: Java

beberapa bulan yang lalu gw ngobrol sama teman yg msh kuliah d kmps gw tercinta! katanya dia dapet tugas suruh buat program java untuk ngirim email, mungkin telat ya kalo gw post sekarang? tapi biarin daripada ga sama sekali!! emoticon ok, nih programnya!

eh… tapi ini gw coba pake email kantor dan berhasil (ga bisa untuk yahoo) tau hostnya yahoo gw blom dapet! tapi sepertinya selain yahoo bisa deh!!

 

package send;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Sender2
{    
    
   public static void main(String[] args)
   {
      String host = "mail.kantor.com";
      
  //    String popHost = "pop.mail.yahoo.co.uk";
//      String from = "gw_ok@yahoo.com";
      
      String username = "gw_keren@kantor.com";
      String password = "adadeh";

      String recipientEmailAddress = "gw_ok@yahoo.com";
      
      String message_cc = "teman_gw@yahoo.co.id";
      
      
      Transport transport = null;
      
      try
      {
                    
         final InternetAddress sender    = new InternetAddress(username);
         final InternetAddress recipient = new InternetAddress(recipientEmailAddress);
         final InternetAddress ccAddress = new InternetAddress(message_cc);
         
         Properties properties = System.getProperties();
         properties.put("mail.smtp.auth", "true");
         properties.put("mail.smtp.host", host);
         properties.put("mail.smtp.port", "25");
         properties.put("mail.user", sender.getAddress());
         properties.put("mail.password", password);
      
         Session session = Session.getDefaultInstance(properties,null);
         session.setDebug(true);
         
//       Pop Authenticate yourself
  /*       Store store = session.getStore("pop3");
         store.connect(popHost, username, password); */
         
         MimeMessage message = new MimeMessage(session);
         message.setSubject("test subject");
         message.setText("test body program baru pake CC!!sorry");
         message.setFrom(sender);
         message.addRecipient(Message.RecipientType.TO, recipient);
         message.addRecipient(Message.RecipientType.CC, ccAddress);
         message.saveChanges();
         
        // Transport transport = session.getTransport(sender[0]);
         
         transport = session.getTransport("smtp");
         transport.connect(host, sender.getAddress(), password);
      //   transport.connect("smtp.mail.yahoo.com.sg",-1,sender.getAddress(), password);
         transport.sendMessage(message, message.getAllRecipients());
         transport.close();
      }
      catch (MessagingException e)
      {
          System.out.println("this is the error: " + e);
          e.printStackTrace();
      }
      finally
      {
         try
         {
            transport.close();
         }
         catch (Exception e)
         {}
      }
   }
}

 

ya.. klo teman-teman ada yang tau popHost untuk yahoo boleh dong di share biar kita sama-sama belajar!!

ok thx… 

bedanya orang kuliah IT(Komputer) dengan orang kursus Komputer (otodidak)

Filed under: Programming

Waktu kuliah ngambil jurusan IT, banyak temen dan saudara yang bilang "ngapain kamu ngambil jurusan itu? mending ngambil jurusan yg laen aja dan klo mau jago komputer mendingan kursus aja! 3 bulan udah jago deh!!"

miris juga yg tadinya semangat malah di patahin seperti itu! trus gw tanya aja ke dosen "pak kenapa ada jurusan ini? bukannya orang yang cuma kursus 3 bulan aja bisa buat program?"

trus dosen gw jawab dengan bijak "ok, bener bgt tuh kursus 3 bulan jago buat program! TAPI…" nah pake tapi tuh dosen ngomongnya!

"tapi ini bedanya kalian yang duduk di bangku kuliah jurusan ini sama teman kalian yang hanya kursus :

mereka emang hebat program, hanya itu! mereka juga hanya mengenal database dari luar aja! karena meraka sedikit teori dan langsung praktek! sedangkan kalian berawal dari teori, algoritma, sistem database, bisnis proses, ERD, Flochart dan teman - temannya akan di pelajari! secara extreem bedanya adalah bila membangun sebuah program mereka akan langsung coding, tanpa harus memikirkan ERDnya gimana, bisnis prosesnya seperti apa dan teman-temannya! sedangkan kalian yang pertama di kerjakan adalah sebaliknya, coding akan di taruh pada akhir pekerjaan! nah kira - kira seperti itulah sedikit gambaran dari saya!…"

dengan penjelasan yang singkat seperti itu akhirnya membuat saya merasa lega dengan keputusan untuk mengambil jurusan ini!!

oya, ini cuma gambaran aja! bukan maksud gw orang yang kuliah jurusan apa dan belajar komputer dengan kursus (otodidak) itu ga sehebat orang yg lulus dari jurusan IT lho!! banyak juga d dunia kerja itu programmer dari jurusan ekonomi, teknik industri dan lain-lai! mungkin mereka serius memperdalam ilmu komputer di selang kuliah atau setelah lulus dan mungkin tuntutan kerja!

ya, ini biar teman-teman yang ngambil jurusan IT dan niat mengambil jurusan ini tidak merasa seperti yg gw rasain di atas!

ok, cukup segitu dulu deh!! 

Get free blog up and running in minutes with Blogsome
Theme designed by Ian Main