O antigo programador da empresa onde trabalho começou a fazer um sistema de upload de imagens, mas nunca terminou.
Eu decidi "adotar" então o script dele, mas as fotos não são upadas ao servidor.
Esse script deveria redimensionar a foto e criar uma thumb e depois salvar os dois numa pasta.
Alguém consegue ver onde o erro está?
Agradeço desde já!
//Busca o nome do arquivo do formulário $vet_foto = $_FILES["foto"]; //Nome do arquivo de upload temporário $arq_foto = $vet_foto["tmp_name"]; //Pega informações do arquivo $arq_info = getimagesize($arq_foto); //Pega o tamanho da foto $arq_w = $arq_info[0]; $arq_h = $arq_info[1]; //Define o tamanho que a foto deve ter $arq_new_w = 370; $arq_new_h = 260; $thumb_w = 120; $thumb_h = 80; //Checa se a foto escolhida tem o tamanho mínimo para upload if($arq_w >= $arq_new_w || $arq_h >= $arq_new_h) { //Pega o tipo mime do arquivo enviado $arq_mime = $arq_info["mime"]; if($arq_mime == "image/jpeg") { //Gera o nome do arquivo a ser salvo com base no id (pasta chmod 0777) $arq_foto_new = "upado/$id.jpg"; $arq_thumb_new = "upado/$id.thumb.jpg"; //Define o tamanho para redimensionamento proporcional da foto $currwidth = $arq_w; $currheight = $arq_h; $maxwidth = $arq_new_w; $maxheight = $arq_new_h; if($currwidth > $currheight && $currwidth > $maxwidth) { $percent = ($maxwidth * 100) / $currwidth; $nwidth = $maxwidth; $nheight = ($percent * $currheight) / 100; } else if($currwidth < $currheight && $currheight > $maxheight) { $percent = ($maxheight * 100) / $currheight; $nheight = $maxheight; $nwidth = ($percent * $currwidth) / 100; } else { $nwidth = $maxwidth; $nheight = $maxheight; } $nwidth = intval($nwidth); $nheight = intval($nheight); //Imagem original $src_img = imagecreatefromjpeg($arq_foto); //Imagem redimensionada proporcionalmente $dst_img_res = imagecreatetruecolor($nwidth, $nheight); imagecopyresampled($dst_img_res, $src_img, 0, 0, 0, 0, $nwidth, $nheight, $arq_w, $arq_h); //Criação do thumb $thumb_new = imagecreatetruecolor($thumb_w, $thumb_h); imagecopyresampled($thumb_new, $dst_img_res, 0, 0, 0, 0, $thumb_w, $thumb_h, $nwidth, $nheight); //Imagem cortada para o tamanho correto após redimensionamento $dst_img = imagecreatetruecolor($maxwidth, $maxheight); imagecopy($dst_img, $dst_img_res, 0, 0, 0, 0, $maxwidth, $maxheight); //Cria e salva a imagem em um arquivo com qualidade 70 $arq_foto_new_ok = imagejpeg($dst_img, "$arq_foto_new", 70); $arq_thumb_new = imagejpeg($thumb_new, "$arq_thumb_new", 40); } }
Edição feita por: Forgotten Canha, 30/01/2007, 16:08.