I'm trying to mount a system that checks the mime type of the image when uploading. But it is giving an error.
Follow the code:
<?php
$action = addslashes(filter_input(INPUT_GET, 'action',FILTER_SANITIZE_SPECIAL_CHARS));
if ((!empty($action)) and ($action == "add")) {
// Recebe a imagem
$imagem = $_FILES["imagem"];
$size = getimagesize($imagem);
switch ($size['mime']) {
case "image/gif":
echo "Image is a gif";
break;
case "image/jpeg":
echo "Image is a jpeg";
break;
case "image/png":
echo "Image is a png";
break;
case "image/bmp":
echo "Image is a bmp";
break;
}
}
?>
<form name='form' method='post' action='?action=add' enctype='multipart/form-data'>
<input type="file" name="imagem">
<input type="submit" value="ok">
</form>
Error log:
Warning: getimagesize () expects parameter 1 to be string, array given in /Library/WebServer/Documents/teste.php on line 12
The error occurs on this line:
$size = getimagesize($imagem);
Modified to
$ image = $ _FILES ['image'] ['tmp_name'];
But returns error in getimagesize()
. "Parameter can not be empty"