Jumat, 05 Desember 2014

Upload file dengan HTML5 dan PHP









Berikut kodennya..!

index.html

<!DOCTYPE html>
<html>
<head>
<script>

function uploadFile() {
    // membaca data file yg akan diupload, dari komponen 'fileku'
    var file = document.getElementById("fileku").files[0];
    var formdata = new FormData();
    formdata.append("datafile", file);

    // proses upload via AJAX disubmit ke 'upload.php'
    // selama proses upload, akan menjalankan progressHandler()
    var ajax = new XMLHttpRequest();
    ajax.upload.addEventListener("progress", progressHandler, false);
    ajax.open("POST", "upload.php", true);
    ajax.send(formdata);
}

function progressHandler(event){
    // hitung prosentase
    var percent = (event.loaded / event.total) * 100;
    // menampilkan prosentase ke komponen id 'progressBar'
    document.getElementById("progressBar").value = Math.round(percent);
    // menampilkan prosentase ke komponen id 'status'
    document.getElementById("status").innerHTML = Math.round(percent)+"% telah terupload";
    // menampilkan file size yg tlh terupload dan totalnya ke komponen id 'total'
    document.getElementById("total").innerHTML = "Telah terupload "+event.loaded+" bytes dari "+event.total;
}

</script>
</head>
<body>

<h2> HTML5 Upload File</h2>
<form id="upload_form" enctype="multipart/form-data">
   <input type="file" name="datafile" id="fileku"><br>
   <input type="button" value="Upload File" onclick="uploadFile()">
   <progress id="progressBar" value="0" max="100" style="width:300px;"></progress>
   <h3 id="status"></h3>
   <p id="total"></p>
</form>
</body>
</html>


___________________________________________

upload.php

<?php
// baca nama file
$fileName = $_FILES["datafile"]["name"];
// baca file temporary upload
$fileTemp = $_FILES["datafile"]["tmp_name"];
// baca tipe file
$fileType = $_FILES["datafile"]["type"];
// baca filesize
$fileSize = $_FILES["datafile"]["size"];

// proses upload file ke folder /upload
if (move_uploaded_file($fileTemp, 'upload/'.$fileName)){
    echo "Upload $fileName selesai";
}
?>

_________________________________

Kursus / Konsultasi / Bimbingan Belajar / Skripsi Mahasiswa
http://www.lp2maray.com
021-92771708   / 085279959498

Selasa, 02 Desember 2014

Membuat fom anggota dengan PHP

















Berikut kodenya :

1. kode jam dan tanggal 

<?php
$tglsekarang=date("Y-m-d");
$jamsekarang=date("H:i:s");
echo "Tanggal: ".TGLINDO($tglsekarang)." Jam ".$jamsekarang." WIB";
?>

2. kode pemanggilan tgl, bulan, tahun.

<?php
  for($i=1;$i<=31;$i++){
if($i<10){$i="0".$i;}
echo"<option value=$i>$i</option>";
}
?>
      </select>
      <select name="bulanlhr" id="bulanlhr">
        <?php
for($i=1;$i<=12;$i++){
$namabulan=BLNINDO($i);
echo"<option value=$namabulan>$namabulan</option>";
}
?>
      </select>
      <select name="tahunlhr" id="tahunlhr">
<?php
 $thnawal=date("Y")-50;
 $thnakhir=date("Y")-13;
 for($i=$thnawal;$i<=$thnakhir;$i++){
echo"<option value=$i>$i</option>";
}
?>


3. kode pemanggilan variable

<?php
if(isset($_POST["simpan"])){
$nim=$_POST["nim"];
$nama=$_POST["nama"];
$jeniskelamin=$_POST["jeniskelamin"];
$agama=$_POST["agama"];
$hobbies1=$_POST["hobbies1"];
$hobbies2=$_POST["hobbies2"];
$hobbies3=$_POST["hobbies3"];
$foto=$_POST["foto"];
$tgldaftar=TGLINDO(date("Y-m-d"));
$tanggallhr=$_POST["tanggallhr"];
$bulanlhr=$_POST["bulanlhr"];
$tahunlhr=$_POST["tahunlhr"];
$tgllahir="$tanggallhr $bulanlhr $tahunlhr";
$alamat=$_POST["alamat"];
$beasiswa=rand(100000,1000000);
   $beasiswa=RUPIAH($beasiswa);

  $hobbies="";
 if(!empty($hobbies1)){$hobbi=$hobbi."".$hobbies1;}
 if(!empty($hobbies2)){$hobbi=$hobbi."".$hobbies2;}
 if(!empty($hobbies3)){$hobbi=$hobbi."".$hobbies3;}
  $hobbi=trim($hobbi);

    if($_FILES["foto"]!=""){
  @copy($_FILES["foto"]["tmp_name"],"image/".$_FILES["foto"]["name"]);
  $foto=$_FILES["foto"]["name"];
  }
else{$foto="avatar.jpg";}
if(strlen($foto)<1){$foto="avatar.jpg";}

echo "<br/><br/><pre>
   Selamat Datang<br/>
Nim        :$nim
Nama       :$nama
Tgl-Lahir  :$tgllahir
Gender     :$jeniskelamin
Hobbies    :$hobbi
Agama      :$agama
Foto       :<img src='image/$foto' width='80' height='80'>
Alamat     :$alamat
Beasiswa   :Rp.$beasiswa
         
   Terima Kasih
                             Administrator : $tgldaftar;
</pre>";
}
?>


--------------------------------------------------------------------------------------------------
Kursus / Konsultasi / Bimbingan Belajar / Skripsi Mahasiswa
http://www.lp2maray.com
021-92771708   / 085279959498

Minggu, 30 November 2014

Audio dengan HTML5




Berikut kodenya.,

<section style="text-align:center"><audio controls>
<source src="audio/Adele -Set Fire To The Rain.mp3" type="audio/mp3">
Browser anda tidak mendukung

</audio></section>

Kursus / Konsultasi / Bimbingan Belajar / Skripsi Mahasiswa
http://www.lp2maray.com
021-92771708   / 085279959498

Cara membuat video dengan HTML5



















Berikut kodenya.,

<!DOCTYPE HTML>
<html>
<body>
<video width="320" height="240" controls>
<source src="video/Ahmed Bukhatir l Prophet of Peace.mp4" type="video/mp4" />
<source src="movie.ogg" type="video/ogg" />
browser anda tidak mendukung...!
</video>
</body>
</html>

________________________________________________

Kursus / Konsultasi / Bimbingan Belajar / Skripsi Mahasiswa
http://www.lp2maray.com
021-92771708   / 085279959498