0
Good, I have this code that after filling 1 form uploading with an image, this code puts the image that was uploaded in 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’t, but if I upload a photo with the sizes 264*261 pixels I can already.
How can I fix this, to put maximum sizes of 4000x4000 pixels?
Thank you
There’s nothing in your code that limits image resolution, so the problem of not being able to send high-resolution images is nowhere else. Maybe in the file size, you checked if you have 5Mb or less? Check the PHP upload limit in the php.ini file and on your web server. I don’t know about Apache, but Nginx has an upload limit too and you can increase / decrease in the conf file.
– Clayderson Ferreira
$maxSize = 1024 * 1024 * 5;
Have you tried increasing this? Apparently that’s what you have in your code limiting file size. Now, why allow 4000x4000 upload? Are you sure that’s what you need?– Bacco
Problem Solved!
– Gonçalo