good day , here i have a page that store data with some images in it , 3 images to be exact,
<?php
$brg = $_POST['id'];
$nama = $_POST['nm'];
$img = $_FILES['img']['name'];
$tmp = $_FILES['img']['tmp_name'];
$img1 = $_FILES['img1']['name'];
$tmp1 = $_FILES['img1']['tmp_name'];
$img2 = $_FILES['img2']['name'];
$tmp2 = $_FILES['img2']['tmp_name'];
$temp = explode(".", $img);
$temp1 = explode(".", $img1);
$temp2 = explode(".", $img2);
$new = round(microtime(true)) . '.' . end($temp);
$new1 = round(microtime(true)) . '.' . end($temp1);
$new2 = round(microtime(true)) . '.' . end($temp2);
$path = "img/photo/".$new;
$path1 = "img/photo/".$new1;
$path2 = "img/photo/".$new2;
move_uploaded_file($tmp, $path);
move_uploaded_file($tmp1, $path1);
move_uploaded_file($tmp2, $path2);
$c = "insert into imgstuff values('$brg','$nama','$new','$new1','$new2');";
$ins=mysqli_query($con,$c);
if($ins){
header('location: test.php?success='.base64_encode('success'));
} else {
header('location: test.php?error='.base64_encode('failed'));
}
?>
code above works perfectly but as you can see it ends up horribly ugly and it produce same file name for three picture ,
my question, is there any ways to made my code cleaner and easy to maintain and whats wrong with my naming files method ?