Enlarge image size

0

Well, I have this code that after filling 1 form uploading with an image, this code places the image that was uploaded into a folder.

Code:

<?php
error_reporting(0);
include("config.php");
$idcarro = $_POST["idcarro"];
    if(isset($_POST['upload'])){

        //INFO IMAGEM
        $file       = $_FILES['img'];
        $numFile    = count(array_filter($file['name']));

        //PASTA
        $folder     = 'imgcarros';

        //REQUISITOS
        $permite    = array('image/jpeg', 'image/png');
        $maxSize    = 1024 * 1024 * 5;

        //MENSAGENS
        $msg        = array();
        $errorMsg   = array(
            1 => 'O arquivo no upload é maior do que o limite definido em upload_max_filesize no php.ini.',
            2 => 'O arquivo ultrapassa o limite de tamanho em MAX_FILE_SIZE que foi especificado no formulário HTML',
            3 => 'o upload do arquivo foi feito parcialmente',
            4 => 'Não foi feito o upload do arquivo'
        );

        if($numFile <= 0){
            echo 'Selecione uma Imagem!';
        }else{
            for($i = 0; $i < $numFile; $i++){
                $name   = $file['name'][$i];
                $type   = $file['type'][$i];
                $size   = $file['size'][$i];
                $error  = $file['error'][$i];
                $tmp    = $file['tmp_name'][$i];

                $extensao = @end(explode('.', $name));
                $novoNome = rand().".$extensao";

                if($error != 0){
                    $msg[] = "<b>$name :</b> ".$errorMsg[$error];
                }else if(!in_array($type, $permite)){
                    $msg[] = "<b>$name :</b> Erro imagem não suportada!";
                }else if($size > $maxSize){
                    $msg[] = "<b>$name :</b> Erro imagem ultrapassa o limite de 5MB";
                }else{

                    if(move_uploaded_file($tmp, $folder.'/'.$novoNome)){
                        $sql = mysqli_query($link, "INSERT INTO imgcarros (idcarro, img) VALUES ('$idcarro', '$folder/$novoNome')");
                        $verifica = mysqli_query($link, "SELECT * FROM carros where id='$idcarro'");
                        $array = mysqli_fetch_array($verifica);


?>

<script type="text/javascript">

window.alert("Foto enviada com Sucesso!");

</script>
<?php





                    }else{
                        $msg[] = "<b>$name :</b> Desculpe! Ocorreu um erro...";

                }

                foreach($msg as $pop){
                    echo $pop.'<br>';
            }
        }
    }
        }
    }

But I want to upload a photo with the dimensions: 2380x1422 pixels, but I can not, but if I upload a photo with the sizes 264 * 261 pixels I already can.

How can I fix this, to put maximum sizes of 4000x4000 pixels?

Thank you

    
asked by anonymous 10.04.2016 / 13:44

1 answer

2

The code you submitted does not validate the dimensions (width, height).

Probably the problem may be in weight validation or to mime type.

Upload weight limit in PHP

In PHP settings, set the value in the upload_max_filesize directive.

If you do not know how much is set, just do this:

echo ini_get('upload_max_filesize ');

Returns the limit in bytes.

Input hidden MAX_FILE_SIZE

Also check that the HTML form contains MAX_FILE_SIZE . Because it has priority over upload_max_filesize of PHP, if it is smaller. Note that more modern browsers ignore this parameter. As a precaution, for older browsers, it is good to specify. Finally, the choice depends on the target audience.

Code size limit

In the code you posted there is also a specific limit defined in the $maxSize variable. The limit is 5mb.

Increase the limit if necessary.

Mime type and variations of JPG types.

Another point that may be preventing uploading is the allowed file types defined in the $permite

$permite = array('image/jpeg', 'image/png');

JPG types have variations. It is also recommended to add such variations:

$permite = array(
    'image/jpeg',
    'image/jpg',
    'image/pjpg',
    'image/pjpeg',
    'image/png'
);
    
10.04.2016 / 14:18