Tampilkan postingan dengan label php. Tampilkan semua postingan
Tampilkan postingan dengan label php. Tampilkan semua postingan

Senin, September 26, 2011

phpMyAdmin : How to Import Large CSV

Case : You have a big file size csv to import to mysql using phpmyadmin
Solution : Use mysql script instead of import form from phpmyadmin (that will save you a lot of time)
Script :
LOAD DATA LOCAL INFILE 'file_name.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(column1,column2,column3);


Note : place your csv file in your phpmyadmin directory

Source : http://www.phpfreaks.com/forums/index.php?topic=343906.0

Sabtu, Juli 23, 2011

PHP : Fungsi Terbilang

function kekata($x) {
 $x = abs($x);
 $angka = array("", "satu", "dua", "tiga", "empat", "lima",
 "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
 $temp = "";
 if ($x <12) {
  $temp = " ". $angka[$x];
 } else if ($x <20) {
  $temp = kekata($x - 10). " belas";
 } else if ($x <100) {
  $temp = kekata($x/10)." puluh". kekata($x % 10);
 } else if ($x <200) {
  $temp = " seratus" . kekata($x - 100);
 } else if ($x <1000) {
  $temp = kekata($x/100) . " ratus" . kekata($x % 100);
 } else if ($x <2000) {
  $temp = " seribu" . kekata($x - 1000);
 } else if ($x <1000000) {
  $temp = kekata($x/1000) . " ribu" . kekata($x % 1000);
 } else if ($x <1000000000) {
  $temp = kekata($x/1000000) . " juta" . kekata($x % 1000000);
 } else if ($x <1000000000000) {
  $temp = kekata($x/1000000000) . " milyar" . kekata(fmod($x,1000000000));
 } else if ($x <1000000000000000) {
  $temp = kekata($x/1000000000000) . " trilyun" . kekata(fmod($x,1000000000000));
 }
  return $temp;
}
function terbilang($x, $style=4) {
 if($x<0) {
  $hasil = "minus ". trim(kekata($x));
 } else {
  $hasil = trim(kekata($x));
 }
 switch ($style) {
  case 1:
   $hasil = strtoupper($hasil);
   break;
  case 2:
   $hasil = strtolower($hasil);
   break;
  case 3:
   $hasil = ucwords($hasil);
   break;
  default:
   $hasil = ucfirst($hasil);
   break;
 }
 return $hasil;
}

Source : http://maseko.com/code-snippet/php/fungsi-terbilang/

Rabu, Mei 18, 2011

Mass User Creation in WordPress

Case : you want to add mass user in your wordpress
Script :

require( '/wp-load.php' );
wp_create_user('otto', 'password', 'otto@ottodestruct.com');
wp_create_user('fake', 'fakepass', 'fake@example.com');
...


Source : http://wordpress.org/support/topic/mass-user-creation-in-wordpress-30

Selasa, Maret 29, 2011

PHP : Auto Resize Image on Upload

Case : you want to resize image on upload
Solution : PHP imagecopyresampled
Script :

if ($_SESSION[username_administrasi] != "" && $_POST[submit] == "Simpan") {
$cek = cek("select * from ktp where no_ktp = '$no_ktp' and npwp = '$npwp' ");
if ($cek > 0) {
alert("Data sudah ada !");
loncat("../index.php");
} else {
$tmp_filename = $_FILES[file1][tmp_name];
$filename = $_FILES[file1][name];
$file = explode(".",$filename);
$nama_file = $file[0];
echo $nama_file;
list($old_width, $old_height, $type, $attr) = getimagesize($tmp_filename);
if ($type == 1 || $type == 2 || $type == 3) {
if (($_FILES["file1"]["size"]/1024) > 250) {
if ($type == 1) {
$new_image = imagecreatefromgif($tmp_filename);
} else if ($type == 2) {
$new_image = imagecreatefromjpeg($tmp_filename);
} else if ($type == 3) {
$new_image = imagecreatefrompng($tmp_filename);
}

echo "
width asli = ".$old_width;
echo "
height asli = ".$old_height;
$new_width = 800;

if ($old_width > $old_height) {
$percentage = ($new_width / $old_width);
} else {
$percentage = ($new_width / $old_height);
}

$new_width = round($old_width * $percentage);
$new_height = round($old_height * $percentage);

echo "
width resize = ".$new_width;
echo "
height resize = ".$new_height;

echo "
".$_FILES[file1][type];
echo "
".$_FILES[file1][size];


if (function_exists(imagecreatetruecolor)){
$resized_img = imagecreatetruecolor($new_width,$new_height);
}else{
die("Error: Please make sure you have GD library ver 2+");
}

imagecopyresampled($resized_img, $new_image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);

if ($type == 1) {
imagegif($resized_img,"../images/uploaded/tumb_".$nama_file.".gif");
} else if ($type == 2) {
imagejpeg($resized_img,"../images/uploaded/tumb_".$nama_file.".jpg");
} else if ($type == 3) {
imagepng($resized_img,"../images/uploaded/tumb_".$new_image.".png");
}

$move = move_uploaded_file($_FILES['file1']['tmp_name'], '../images/uploaded/real_'.$filename);

ImageDestroy ($resized_img);
ImageDestroy ($new_image);

loncat("../index.php");
} else {

$move = move_uploaded_file($_FILES['file1']['tmp_name'], '../images/uploaded/real_'.$filename);

if ($move) {
alert("Upload sukses.");
} else {
alert("Upload gagal.");
}
loncat("../index.php");
}
} else {
alert(" Tipe file yang diijinkan : GIF, JPG, JPEG, PNG");
//loncat("../index.php");
}
}
}



Source : http://www.php.net/

Rabu, Januari 26, 2011

JQuery : Delete row and fade out the row affected

Case : You want to delete row without refreshing whole page
Solution : Use JQuery


function hapus(id){
if (confirm('Yakin mau dihapus ???')) {
$.post('actions/hapus_pengeluaran.php', {id: +id, ajax: 'true' },
function(){
$("#row_"+id).fadeOut("slow");
});
}
}


Source : http://www.bitsntuts.com/css/simple-jquery-delete-table

Jumat, Desember 17, 2010

PHP MySQL JQuery - Autocomplete







http://www.uri.edu/blog/2009/06/08/auto-complete-with-jquery-php-and-mysql/

Minggu, Agustus 08, 2010

XAMPP : XAMPP Windows 1.7.3 problem after installation

Case: Install / upgrade xampp to the new version (1.7.3)

Problem: After a successful installation, the . php files can not be read by browsers

Solution: Edit the php.ini, search for "short_open_tag" (default value: Off), make it "On
"









Credit to : dhanuxz senyum

Thank you

Sabtu, November 28, 2009

xampp + coldfusion 7

download :

xampp-win32-1.7.2.exe

coldfusion7

hotfix wsconfig.jar
  1. Backup cf_root/runtime/lib/wsconfig.jar to wsconfig.jar.bu.
  2. Download hot fix (2.3MB).
  3. Stop all ColdFusion servers and Apache 2.2
  4. Extract the new wsconfig.jar file and place it in cf_root/runtime/lib.
  5. Start - Program - Macromedia - ColdFusion MX 7 - Web Server Configuration Tool

































Start apache and coldfusion server stres