0
I’m trying to set up a system that checks the mime type image when uploading. However.
Follows 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
Error occurs on this line:
$size = getimagesize($imagem);
I modified it to
$image = $_FILES['image']['tmp_name'];
But returns error in getimagesize()
. "Parameter cannot be Empty"
made a mistake
Warning: getimagesize(102.jpg): failed to open stream: No such file or directory in /Library/WebServer/Documents/teste.php on line 8
line 8 is$imagem = $_FILES['imagem']['tmp_name'];
– Hugo Borges
Strange because
tmp_name
does not return the original name. It returns the absolute path of the temporary file. The name is serialized, something like a md5 format. Clear the doubt by making a breakpoint withprint_r()
as commented in the reply.– Daniel Omine
updated my question with the new code. give a look there please
– Hugo Borges
Do not modify the whole question. When so just add some new information below the question. I reversed and put the new information. But, for the third time, I ask you to put the breakpoint with
print_r()
. Without proper feedback I can’t continue.– Daniel Omine
excuse my ignorance, but where should I put the print_r();?
– Hugo Borges
look I realized that I copy the image to the folder to where this php file, the error does not occur. it seems that the system only reads the image if it is on the server.
– Hugo Borges
The image is on the server, otherwise the copy would not be possible.
– Daniel Omine