Jumat, 19 Januari 2018

kodingan Dinas pengarsipan Daerah

index.php
<!DOCTYPE html>
<html>
<head>
<title>DINAS PENGARSIPAN DAERAH</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<div id="container">
    <div id="header">
    <h1>DINAS PENGARSIPAN DAERAH</h1>
            <span>PROVINSI DIY</span>
        </div>
       
        <div id="menu">
        <a href="index.php" class="active">Home</a>
            <a href="upload.php">Upload</a>
            <a href="download.php">Download</a>
        </div>
       
        <div id="content">
        <h2>Home</h2>
            <p>Selamat Datang!</p>
            <a href="logout.php">LOGOUT</a>
        </div>
    </div>

</body>
</html>

login.xml
<!DOCTYPE html>
<html>
<head>
 <title>Form Login</title>
 <link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
 <div class="login">
  <div class="container">
   <div class="box">
    <h1>Silahkan Masukan Username dan Password anda</h1><br>
    <form method="post" action="login.php">
     <label>Username</label><br>
     <input type="text" name="user" maxlength="10"><br><br>
     <label>Password</label><br>
     <input type="password" name="pass" maxlength="10"><br><br>
     <input type="submit" name="simpan" value="Login">
    </form>
   </div>
  </div>
 </div>
</body>
</html>

login.php
<?php
if(isset($_POST['simpan'])){
 $user = $_POST['user'];
 $pass = $_POST['pass'];

 $conn = mysqli_connect('localhost', 'root', '', 'upload');
  if(mysqli_connect_errno()){
   echo "Koneksi Ke Server Gagal";
   exit();
  }

 $sql="select * from t_login where username='".$user."'AND password='".$pass."'";
    $result=mysqli_query($conn, $sql);
    $num_rows=mysqli_num_rows($result);
    $row=mysqli_fetch_row($result);
    if($num_rows>0){
        session_start();
        $_SESSION["nama"]=$row['username'];
        $_SESSION["pass"]=$row['password'];
        echo "<script>location='index.php';</script>";
    } else {
        echo "<script>alert('Username atau Password Admin tidak benar !!!');</script>";
        echo "<script>location='login-form.html';</script>";
       
    }
}
?>

logout.php
<?php
session_destroy();
echo "<script>location='login-form.html';</script>";//jika berhasil maka akan kembali ke login form
?>

simpan.php
<?php
// Tentukan folder file yang boleh di download
$folder = "files/";
// Lalu cek menggunakan fungsi file_exist
if (!file_exists($folder.$_GET['files'])) {
  echo "<h1>Access forbidden!</h1>
      <p> Anda tidak diperbolehkan mendownload file ini.</p>";
  exit;
}

// Apabila mendownload file di folder files
else {
  header("Content-Type: octet/stream");
  header("Content-Disposition: attachment;
  filename=\"".$_GET['files']."\"");
  $fp = fopen($folder.$_GET['files'], "r");
  $data = fread($fp, filesize($folder.$_GET['files']));
  fclose($fp);
  print $data;
}
?>

upload.php
<!DOCTYPE html>
<html>
<head>
<title> pegawai</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
       
        <div id="menu">
        <a href="index1.php">Home</a>
            <a href="upload.php" class="active">Upload</a>
            <a href="download.php">Download</a>
        </div>
       
        <div id="content">
        <h2>Upload</h2>
         
            <form enctype="multipart/form-data" method="POST" action="hasil_upload.php">
            <table width="100%" align="center" border="0" bgcolor="#eee" cellpadding="2" cellspacing="0">
File yang di upload : <input type="file" name="fupload"><br>
Deskripsi File : <br>
<textarea name="deskripsi" rows="8" cols="40"></textarea><br>
<input type=submit value=Upload>
</table>
</form>
            </p>
        </div>
    </div>
           
</body>
</html>

hasil upload.php
?php
// Baca lokasi file sementar dan nama file dari form (fupload)
$lokasi_file = $_FILES['fupload']['tmp_name'];
$nama_file   = $_FILES['fupload']['name'];
// Tentukan folder untuk menyimpan file
$folder = "files/$nama_file";
// tanggal sekarang
$tgl_upload = date("Ymd");
// Apabila file berhasil di upload
if (move_uploaded_file($lokasi_file,"$folder")){
  header("location:download.php");
 
  // Masukkan informasi file ke database
  $konek = mysqli_connect("localhost","root","","pegawai");

  $query = "INSERT INTO upload (nama_file, deskripsi, tgl_upload)
            VALUES('$nama_file', '$_POST[deskripsi]', '$tgl_upload')";
           
  mysqli_query($konek, $query);
}
else{
  echo "File gagal di upload";
}
?>

Tidak ada komentar:

Posting Komentar