Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function upload image
- // view username
- function check_username($query)
- {
- global $link;
- $query = "SELECT username FROM tb_admin";
- $result = mysqli_query($link, $query);
- return $result;
- }
- // edit profile
- function edit_profile($username, $password)
- {
- global $link;
- $query = "UPDATE tb_admin SET username = '$username', password = '$password'";
- if ( mysqli_query($link, $query) ) return true;
- else return false;
- }
- // check image size
- function check_size($image_size)
- {
- if ( 500000 < $image_size ) return true;
- else return false;
- }
- // check image format
- function check_format($imageFormat)
- {
- if ( $imageFormat == "jpg" && $imageFormat == "jpeg" && $imageFormat == "png") {
- return true;
- }else{
- return false;
- }
- }
- // upload image
- function upload_image($tmp_name, $target_file, $target_dir)
- {
- if (move_uploaded_file($tmp_name, $target_file)) {
- return true;
- } else {
- return false;
- }
- }
- // form input
- <form class="form" method="POST" action="" enctype="multipart/form-data">
- <h4 class="form-section">
- <i class="icon-clipboard4"></i> Edit Profile
- </h4>
- <?php
- if ( isset( $_POST['simpan']) ) {
- $username = $_POST['username'] ?? '';
- $password = $_POST['password'] ?? '';
- $image_size = $_FILES['images']['size'];
- $target_dir = "pages/profile/uploads/";
- $tmp_name = $_FILES["images"]["tmp_name"];
- $target_file = $target_dir . basename($_FILES["images"]["name"]);
- $imageFormat = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
- if ( check_format($imageFormat) ) {
- ?>
- <div class="alert alert-warning alert-dismissible fade in mb-2" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- <strong>Warning!</strong> Format hanya boleh jpg, jpeg dan png.
- </div>
- <?php
- }
- if ( check_size($image_size) ) {
- ?>
- <div class="alert alert-warning alert-dismissible fade in mb-2" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- <strong>Warning!</strong> Ukuran foto maksimal 500Kb.
- </div>
- <?php
- }
- if ( !empty(trim($username)) && !empty(trim($password)) ) {
- if ( edit_profile( $username, $password ) ) {
- $profil_pict = upload_image($tmp_name, $target_file, $target_dir);
- ?>
- <div class="alert alert-success alert-dismissible fade in mb-2" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- <strong>Berhasil!</strong> Profile berhasil di edit.
- </div>
- <script type="text/javascript">
- window.location.href = '?pages=profile';
- </script>
- <?php
- }else {
- ?>
- <div class="alert alert-danger alert-dismissible fade in mb-2" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- <strong>Halo!</strong><br> Ada masalah saat menambah data!
- </div>
- <?php
- }
- }else{
- ?>
- <div class="alert alert-danger alert-dismissible fade in mb-2" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- <strong>Halo!</strong><br> Form tidak boleh kosong!
- </div>
- <?php
- }
- }
- ?>
- <div class="form-group">
- <label for="username">Username</label>
- <input type="text" id="username" class="form-control" placeholder="Masukan Username Baru" name="username" autocomplete="off" required>
- </div>
- <div class="form-group">
- <label for="password">Password</label>
- <input type="password" id="password" class="form-control" placeholder="Masukan Password Baru" name="password" autocomplete="off" required>
- </div>
- <div class="form-group">
- <label>Select File</label>
- <label id="projectinput7" class="file center-block">
- <input type="file" id="file" name="images" required>
- <span class="file-custom"></span>
- </label>
- </div>
- <div class="form-actions">
- <button type="submit" class="btn btn-info" name="simpan">
- <i class="icon-android-checkmark-circle"></i> Edit Profile
- </button>
- </div>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement