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 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 27, 2008

buat laporan dengan HTML?

Filed under: PHP

waduh, di tempat kerja gw d haruskan pake PHP! (padahal waktu kuliah belajar PHP gw ga pernah ngerti.. emoticon nertinya cuma HTML itu juga ga di perdalamin!! emoticon) biasa manusia klo udah tuntutan pasti usahanya keras dan alhamdulillah jd jatuh hati nih ke PHP!!hehehe..

mentok waktu di suruh buat laporan! maunya kaya crystal report, ternyata ga ada! jd pake HTML aja deh!! emoticon

masih aja ada masalah, walaupun boleh tanpa tombol print yaitu pake File -> Print.. tapi gw kurang puas dengan itu! emoticon

tanya-tanya temen an konsultasi sama mbah google ternyata dapet juga dengan ga habis 1 hari! emoticon

ni codingnya :

Buat tombolnya printnya di halamn preview report

<input type="button" name="btn_cetak" onClick="cetak(<?php echo $param;?>)" value="Cetak">

Buat script javascript diantara tag<head></head>

<script language="javascript">
function cetak(param){
window.open("cetak.php?param="+param,"cetak","width=500,heigth=500,scrollbars=1")
}
</script>

Di cetak php
<body onload="window.print()">
<?php
$param=$_GET[’param’];
$sql="select ….. from … where field=’$param’";
//buat tampa button
?>
</body>

Sehingga jika cetak.php diload maka akan langsung muncul dialog priint

eh, itu dapet dari orang!(bukan gw yg buat) ini cuma media penyampaian aja.. (semoga membantu) maklum blom menguasai (masih ngeja nih) emoticon

tapi itu gw juga masih blom puas!! karena bisa ngeliat hasilnya kalo udah di print aja! ok akhirnya cari-cari lagi dan mbah google sangat amat baik ngasih gw script seprti ini :

<html>
<head>
<title>Tes</title>

<style type="text/css">
@media print {
input.noPrint { display: none; }
}
</style>

</head>
<body>

<?php
class orang {
var $nama = ‘Nyoba Print’;
var $tinggal = ‘Di HTML’;
}
$new_plesh=new orang();
echo "Tugas saya adalah ".$new_plesh->nama;
echo "<br>";
echo "Tinggal di :".$new_plesh->tinggal;

?>
<form><input class="noPrint" type="button" value="Print" onclick="window.print()"></form>

</body>
</html>

dengan itu gw baru berasa puas!

pertamanya sih tombol printnya pun ikut ke print, tapi pas pake css itu selesai juga 1 masalah gw! alhamdulillah

thx ya Allah…

nb : semoga berguna 

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