1
Good night! I would like to upload a maximum of 5 images and at the same time manipulate them with the Wideimage library. But with the code done so far only the upload is working. I am using the library for the first time, so I do not have so much experience... I hope someone can help me. Thanks in advance!
$images = $_FILES['fotos'];
$name = $images['name']; //Atribui uma array com os nomes dos arquivos à variável
$tmp_name = $images['tmp_name']; //Atribui uma array com os nomes temporários dos arquivos à variável
$allowedExts = array(".gif", ".jpeg", ".jpg", ".png"); //Extensões permitidas
$data_dir = date("Y.m.d-H.i.s");
mkdir("fotos_noticia/" . $data_dir, 0777);
$dir = 'fotos_noticia/' . $data_dir . "/";
$img = array();
$i = 0;
//------------------------------------------------------------------------------------
for ($i = 0; $i < sizeof($tmp_name); $i++) {
$ext = strtolower(substr($name[$i], -4));
if (in_array($ext, $allowedExts) && sizeof($tmp_name) <= 5) { //Pergunta se a extensão do arquivo, está presente no array das extensões permitidas
$new_name = $i . $ext;
$img[$i] = $new_name;
$image = \WideImage::load($tmp_name[$i]); //Carrega a imagem utilizando a WideImage
$image = $image->resize(450, 300, 'outside'); //Redimensiona a imagem para 170 de largura e 180 de altura, mantendo sua proporção no máximo possível
$image = $image->crop('center', 'center', 450, 300); //Corta a imagem do centro, forçando sua altura e largura
move_uploaded_file($tmp_name[$i], $dir.$new_name);
before anything else, I already suggest using another library, I used the wide for a while
– Wees Smith
I thought about it. Suggest me which one? Note: I only posted because I would like to know if there is error in the logic I used. If you identify sends me an opinion. Thanks!
– Bruno Carvalho Camargo
https://github.com/gumlet/php-image-resize this is good
– Wees Smith
Thanks for the tip!
– Bruno Carvalho Camargo