diff --git a/Controller/AdminController.php b/Controller/AdminController.php index cf1a880f6af7522d951c449f67f905c4e4098e39..31eaffc838619cd648edec802c9a53a378b4e842 100644 --- a/Controller/AdminController.php +++ b/Controller/AdminController.php @@ -59,7 +59,8 @@ class AdminController { return $res->view("Pages/AddSong", [ "auth" => $req->auth, - "added" => false + "added" => false, + "failed" => false, ]); } diff --git a/Controller/LaguController.php b/Controller/LaguController.php index b3054ccb7db2fdd2114ede6ac4efe3a157d51b6d..a803b858aa116966f70edbec8cf78361a7a1757e 100644 --- a/Controller/LaguController.php +++ b/Controller/LaguController.php @@ -269,6 +269,15 @@ class LaguController $target_path_audio = "/"; $target_dir = "audio/"; $file = $formData["file_lagu"]["name"]; + + if( substr($formData["file_lagu"]['type'], 5) !== 'audio'){ + return $res->view("Pages/AddSong", [ + "auth" => $req->auth, + "added" => false, + "failed" => true, + ]); + } + $path = pathinfo($file); $filename = $path['filename']; $ext = $path['extension']; @@ -286,6 +295,15 @@ class LaguController //gambar $target_dir = "image/"; $file = $formData["image_file"]["name"]; + + if( substr($formData["image_file"]['type'], 5) !== 'image'){ + return $res->view("Pages/AddSong", [ + "auth" => $req->auth, + "added" => false, + "failed" => true, + ]); + } + $target_path_image = "/"; if (isset($file) && strlen($file) > 0) { $path = pathinfo($file); @@ -317,7 +335,8 @@ class LaguController } return $res->view("Pages/AddSong", [ "auth" => $req->auth, - "added" => true + "added" => true, + "failed" => false ]); } diff --git a/View/Pages/AddSong.php b/View/Pages/AddSong.php index 524f34366c73fa0e30f02fba3d6a5ebaaafcdd4d..c44545b090999e392f36e27cd01804df86d49eac 100644 --- a/View/Pages/AddSong.php +++ b/View/Pages/AddSong.php @@ -18,6 +18,13 @@ </div> XYZ; }?> +<?php if($failed){ + echo <<<XYZ + <div class="failed__added"> + <p>Format file yang dimasukkan tidak sesuai!</p> + </div> + XYZ; +}?> <div class="insert__song__container"> <form method="POST" action="/lagu/add" enctype="multipart/form-data" > <div class="song__input"> diff --git a/static/css/form.css b/static/css/form.css index 922228c227907880d05f319692699ad2430643e9..438e58ec450dc23024c9274f9d5a6789cfb71413 100644 --- a/static/css/form.css +++ b/static/css/form.css @@ -13,6 +13,14 @@ margin: 10px 0; border-radius: 10px; } + +.failed__added { + padding: 15px; + background-color: rgb(212, 55, 55); + margin: 10px 0; + border-radius: 10px; +} + .remove__button{ background-color: red; }