Problem with PHP

2

I have an HTML code to send a form that carries a photo.

<form method="post" enctype="multipart/form-data">
    <input type="file" name="imagen_subir" id="imagen_subir">
    <button type="submit" class="form-control btn btn-danger" name="submit_perfil" value="<?php echo $id ?>">Cambiar fotografía</button>
</form>

The PHP code at the moment of sending is the following:

<?php
    if(isset($_POST['submit_perfil'])){
        $id_per = $_POST['submit_perfil'];
        $directorio_objetivo = "personas/";
        $archivo_objetivo2 = $directorio_objetivo.basename($_FILES["imagen_subir"]["name"]);
        $archivo_objetivo = $directorio_objetivo.basename($_FILES["imagen_subir"]["name"]="perfil_".$_SESSION['token_per'].".".pathinfo($archivo_objetivo2,PATHINFO_EXTENSION));
        $estado_subida = 1;
        $tipo_de_archivo = pathinfo($archivo_objetivo,PATHINFO_EXTENSION);

        if (isset($_POST['submit'])){
            $comprobar = getimagesize($_FILES["imagen_subir"]["tmp_name"]);
            if ($comprobar !== false){
                //echo "El archivo es una imagen - ".$comprobar["mime"].'.';
                $estado_subida=1;
            }else{
                //echo "El archivo no es una imagen";
                $estado_subida=0;
            }
        }
        //if (file_exists($archivo_objetivo)){
        //  echo "El archivo ya es existente";
        //  $estado_subida=0;
        //}
        if ($_FILES["imagen_subir"]["size"]>5000000){
            //echo "Perdona, el archivo es demasiado grande";
            $estado_subida=0;
        }
        if ($tipo_de_archivo != "jpg"){
            //echo "Debes subir una imagen";
            $estado_subida=0;
        }
        if ($estado_subida==0){
            //echo "Tu archivo no pudo ser subido";
        }else{
            if (move_uploaded_file($_FILES["imagen_subir"]["tmp_name"], $archivo_objetivo)){
                ?>
                <section class="predeterminada-seccion">
                    <h1 style="text-align:center;">La imagen de perfil ha sido correctamente cambiada :)</h1>
                    <a href="subir.php" class="form-control btn btn-primary">Cambiar fotografía nuevamente</a>
                </section>
                <?php
            }else{
                ?>
                <section class="predeterminada-seccion">
                    <h1 style="text-align:center;">El archivo no pudo cargarse. Por favor intentar más tarde.</h1>
                </section>
                <?php
            }
        }
    }?>

There is a problem when the option to take a photograph is chosen on the mobile device (Android).

The application used for taking the picture is "Retrica", with the native camera application works perfect. When the photograph is taken and sent, the image is rotated 90 ° against the relog needles. Why is this happening? I managed to change the name of the file that is being uploaded, and the truth is that I have no idea how I did it. Haha, it's not important anyway. I just need to know why the image is rotated. Is there a fix or do I have an error in the code? Thanks.

    
asked by Mattew Janeey 22.06.2016 в 05:06
source

1 answer

2

The image is rotated due to the metatags EXIF , in your case 90 ° against the needles is the flag 6 . With the function exif_read_data() you could get the value of this flag. For example:

$exif = exif_read_data($archivo_objetivo);
$orientacion = $exif['IFD0']['Orientation'];

This problem probably also happens with iOS devices and not just Android.

    
answered by 22.06.2016 / 06:21
source