Well the point is that I don't know how to validate the following, in the database I capture the url of an image and then show it with a echo
in php, what I'm trying to do is to validate the image, whether it is jpg or png, and then export it in an excel file and the image appears, for this I am using the PHPExcel export library and that is where it gets complicated, it only works if I handle jpg or png but not both at the same time, which is what I try to do to through a validation... code in the library:
//Consulta
$sqli=mysqli_query($conn, "select logo from perfil where idperfil = 1");
foreach ($sqli as $key => $value) {
$value['logo']; //ruta de la imagen
}
?>
<img class="img-responsive" name="imagefile" id="imagefile" src="<?php echo "../".$value['logo']?>" alt="Logo"> //mostrando la imagen
<?php
$fila = 7; //Establecemos en que fila inciara a imprimir los datos
//Validación de imagen en png o jpeg Aqui falla, solo puedo utilizar 1
if($_FILES['imagefile']['type'] == "image/jpg"){
$gdImage = imagecreatefromjpeg("../".$value['logo']);//Logotipo JPG
}elseif($_FILES["imagefile"]["type"] == "image/png"){
$gdImage = imagecreatefrompng("../".$value['logo']);//Logotipo JPG
}
It happens to you because you don't use IF and ELSEIF conditionals well .
Your code could look like this:
Ok, I solved it in the following way, since I can't get the image completely and get the properties, I only have the URL in the database where I store it (
../vistas/img/perfil/15_log2.jpg
), I decided to extract the last 3 characters of the URL string, staying as result (jpg
orpng
) depending on what comes in the query, and that way I got it to work.I hope it works for you.