Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'app/model/class.profile.php';
- $auth_pro = new Profile();
- //mengambil id_profile untuk menampilkan semua data di form editing
- if (isset($_GET['edit_ipro']) && !empty($_GET['edit_ipro'])) {
- $ipro = $_GET['edit_ipro'];
- $stmt_edit = $auth_pro->runQuery("SELECT * FROM profile WHERE id_profile=:ipro");
- $stmt_edit->execute(array(':ipro'=>$ipro));
- $edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
- }
- else {
- $auth_pro->redirect('index.php');
- }
- //Eksekusi update data
- if (isset($_POST['btn-update'])) {
- $nama = $_POST['nama'];
- $imgFile = $_FILES['photo']['name'];
- $tmpDir = $_FILES['photo']['tmp_name'];
- $imgSize = $_FILES['photo']['size'];
- if ($nama == "") {
- $error[] = "Nama masih kosong!";
- }
- elseif ($imgFile) {
- $upload_dir = 'photo/';
- $img_ext = strtolower(pathinfo($imgFile, PATHINFO_EXTENSION));
- $valid_ext = array('jpeg', 'jpg', 'png', 'gif');
- $photo = rand(1000,1000000).".".$img_ext;
- if (in_array($img_ext, $valid_ext)) {
- if ($imgSize < 5000000) {
- unlink($upload_dir.$edit_row['photo']);
- move_uploaded_file($tmpDir, $upload_dir.$photo);
- }
- else {
- $error[] = "Maaf, ukuran foto terlalu besar. Maksimal 5MB!";
- }
- }
- else {
- $error[] = "Maaf, hanya file berekstensi JPG, JPEG, PNG dan GIF yang bisa!";
- }
- }
- else {
- //jika tidak ada gambar yang dirubah. maka tetap gambar yang lama
- $photo = $edit_row['photo']; //Gambar lama dari database
- }
- try {
- if ($auth_pro->updateProfile($nama, $photo, $ipro)) {
- $auth_pro->redirect('index.php?saved');
- }
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- include 'app/view/header.blade.php';
- include 'app/view/menu.blade.php';
- include 'app/view/profile-edit.blade.php';
- include 'app/view/footer.blade.php';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement