I am trying to experiment with mysql and php and am wondering how to only allow png files to be submitted in a file input from a form. This is my code at the current moment
<html>
<head>
<title>Profile Picture</title>
</head>
<body>
<?php
echo "<form action='newpfp.php' method='POST' enctype='multipart/form-data'>
<input type='hidden' name='MAX_FILE_SIZE' value='32768'>
<label for='screenshot'>Select New Profile Picture</label><br>
<input type='file' name='screenshot' id='screenshot'><br>
<input type='submit'>
</form>
";
if(!empty($_FILES['screenshot']['tmpname'])){
$newpfp= $_FILES['screenshot']['name'];
if($newpfp_type=='image/png'){
echo "<script type='text/JavaScript'>
console.log('$newpfp has been added to the thing');
</script>";
$dbc=mysqli_connect('localhost','root','','project')
or die('Something bad happened on line 21');
$query="INSERT INTO portal(profile_picture) VALUES('$newpfp');";
$result=mysqli_query($dbc,$query)
or die('Something happened on line 24');
mysqli_close($dbc)
or die('Something BAD happened on line 26');
}
}else{
echo "<script type='text/JavaScript'>
prompt('That filetype is not allowed; Allowed file types: gifs, jpgs and png');
</script>";
}
?>
</body>
</html>
But when I try to submit a defaultpic.png file into the form, the Javascript prompt that I am using a wrong filetype comes up. How do I fix this problem