Problem when loading image in php

0

I do not know what I'm doing wrong, I try to restrict the files I want to upload ..

 <pre>
<?php
	
 	$nombre = $_POST['nombre'];
  	$foto = $_FILES['foto']['name'];
$archivo= $_FILES['foto']['tmp_name'];
$tipo= $_FILES["foto"]["type"];
$size= $_FILES["foto"]["size"];
$permitidos = array("image/gif","image/png","application/PDF",image/jpg");
$limite_kb = 200;

if(in_array($tipo, $permitidos) && $size <= $limite_kb * 1024){
    echo 'si funciona ';
       } else{ 
     echo 'no funciona el tipo de datos';}
}
</pre>

It always gives me the same result with any file ....

Thanks in advance.

    
asked by Martin Matias 29.06.2018 в 23:37
source

1 answer

0

@ A.Cedano <input type="file" name="foto" accept="image/*" /> I have the form, but that does not stop the user from uploading anything to the application, just click on the "all files" tab and that's it, it would make a mess. But your advice is valid.

@Carmen after doing the var_dump I made some changes: (AND by & &) and the two commas of the array $ allowed by single quotes.

<?php
	
	include 'conexion.php';
	
	if(isset($_POST['registrar'])) {
		$nombre = $_POST['nombre'];
		$foto = $_FILES['foto']['name'];
		$archivo= $_FILES['foto']['tmp_name'];
		$tipo= $_FILES["foto"]["type"];
		$size= $_FILES["foto"]["size"];
		$permitidos = array('image/jpeg','image/jpg','image/gif','image/png');
		$limite_kb = 200 * 1024;

if (in_array($tipo, $permitidos) AND ($size < $limite_kb)) {

			echo 'si funciona <br>'.$limite_kb.'<br>';
			echo var_dump($tipo);
		} else{ echo 'no funciona el tipo de datos <br>'.$limite_kb.'<br>';
			echo var_dump($tipo);} 
?>

and it works well! Thanks to everyone.

    
answered by 30.06.2018 в 12:13