RodrigoGomes Postado Janeiro 28, 2007 Denunciar Share Postado Janeiro 28, 2007 tive que renomea o fórum porque eu mesmo já havia resolvido o problema espero que os moderadores não levem isso a mal.. abaixo a minha dúvida... ;) Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 RodrigoGomes Postado Janeiro 29, 2007 Autor Denunciar Share Postado Janeiro 29, 2007 bom por alguns motivos tenho que escrever tudo de novo..! ;) BOM eu refiz um script de UPLOAD de imagens ele redimensiona e faz o upload, eu add nele pra ele verificar as imagens antes de fazer o upload ele carregava perfeitamente o png, agora ele diz que é formato inválido, abaixo o código:<? include 'config.php'; if($_POST['dir'] != ok ){ echo"<form method=\"POST\" enctype=\"multipart/form-data\" action=\"upload.php\"> <input type=hidden name=dir value=ok> <input type=\"file\" name=\"file\" size=\"20\"><br> <input type=\"submit\" value=\"Submeter\"> </form>"; } $maxLarg = "110"; // Max Width $maxAlt = "110"; // Max Height $maxTam = "400"; // Max Size (Kbytes); $mimeImg = "png"; // Mime Type to save imagefiles $taille = 40; $lettres = "abcdefghijklmnopqrstuvwxyz0123456789"; srand(time()); for ($i=0;$i<$taille;$i++) { $sessid.=substr($lettres,(rand()%(strlen($lettres))),1); $imgid=substr("$sessid", 0, 60); } $dir = "img/perfil/evo/$imgid"; treat_image($_FILES['file']['tmp_name'],$dir,$id,$imgid); function treat_image($filename,$destImage=null,$id,$imgid){ if (!is_file($filename) || is_file($destImage)) return false; if ($destImage===FALSE) $destImage=$filename; global $maxLarg; global $maxAlt; global $maxTam; global $mimeImg; list($width, $height, $type, $attr) = getimagesize($filename); $percent = min(round(($maxLarg / $width),2),round(($maxAlt/$height),2),1); $newwidth = floor($width * $percent); $newheight = floor($height * $percent); switch ($type) { case 2 : $source = imagecreatefromjpeg ($filename); break; case 1 : $source = imagecreatefromgif ($filename); break; case 3 : $source = imagecreatefrompng ($filename); break; default : $stop = true; break; } if(!eregi("^image\/(pjpeg|jpeg|png|gif)$", $_FILES['file']["type"])) { echo"Arquivo em formato inválido! A imagem deve ser jpg, jpeg, gif ou png. Envie outro arquivo"; } else { $dest = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($dest, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); switch($mimeImg){ case "png":imagepng($dest, preg_replace("@\.\w+$@","",$destImage).".png" ); $requete25 = mysql_query("UPDATE users SET pics='evo/$imgid.png' WHERE id_membre='$id'") or die(mysql_error()); echo"Concluido, sua imagem foi carregada com sucesso."; } imagedestroy($source); imagedestroy($dest); return preg_replace("@\.\w+$@","",basename($destImage) ).".$mimeImg"; } } ?>o erro esta em:if(!eregi("^image\/(pjpeg|jpeg|png|gif)$", $_FILES['file']["type"])) { <_< Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 RodrigoGomes Postado Janeiro 29, 2007 Autor Denunciar Share Postado Janeiro 29, 2007 bom é isso aí amigos, obrigado pela ajuda.. :D coloquei a cabeça pra funcionar um pouco, coloquei um echo pra me dizer qual formato de imagem eu tentava carregar usando type, e tinha um x- na frente do png.. :o foi só add x-png que funciono.. :P abaixo o script pra quem quiser e se encontrarem algum erro ou algo mal feito postem.. :) <? //CARREGA AS CONFIGURAÇÕES DO SQL include 'config.php'; //VERIFICA SE O ARQUIVO ESTA UPANDO OU AINDA IRÁ UPAR A IMAGEM, SE ELE NÃO ESTIVER UPANDO VAI EXIBIR O ECHO ABAIXO if($_POST['dir'] != ok ){ echo"<form method=\"POST\" enctype=\"multipart/form-data\" action=\"upload.php\"> <input type=hidden name=dir value=ok> <input type=\"file\" name=\"file\" size=\"20\"><br> <input type=\"submit\" value=\"Submeter\"> </form>"; } //DIMENÇÕES $maxLarg = "110"; // Max Width $maxAlt = "110"; // Max Height $maxTam = "400"; // Max Size (Kbytes); //TIPO DE IMAGEM QUE VAI SALVAR $mimeImg = "png"; // Mime Type to save imagefiles //DAR UM NOME A IMAGEM $taille = 40; $lettres = "abcdefghijklmnopqrstuvwxyz0123456789"; srand(time()); for ($i=0;$i<$taille;$i++) { $sessid.=substr($lettres,(rand()%(strlen($lettres))),1); $imgid=substr("$sessid", 0, 60); } //CAMINHO DA IMAGEM $dir = "img/perfil/evo/$imgid"; treat_image($_FILES['file']['tmp_name'],$dir,$id,$imgid); function treat_image($filename,$destImage=null,$id,$imgid){ if (!is_file($filename) || is_file($destImage)) return false; if ($destImage===FALSE) $destImage=$filename; global $maxLarg; global $maxAlt; global $maxTam; global $mimeImg; list($width, $height, $type, $attr) = getimagesize($filename); $percent = min(round(($maxLarg / $width),2),round(($maxAlt/$height),2),1); $newwidth = floor($width * $percent); $newheight = floor($height * $percent); switch ($type) { case 2 : $source = imagecreatefromjpeg ($filename); break; case 1 : $source = imagecreatefromgif ($filename); break; case 3 : $source = imagecreatefrompng ($filename); break; default : $stop = true; break; } //VERIFICA SE O ARQUIVO É IMAGEM if(!eregi("^image\/(pjpeg|jpeg|png|x-png|gif)$", $_FILES['file']["type"])) { echo"Arquivo em formato inválido! A imagem deve ser jpg, jpeg, gif ou png. Envie outro arquivo"; //SE ESTIVER TUDO OK ELE CARREGA } else { $dest = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($dest, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); switch($mimeImg){ case "png":imagepng($dest, preg_replace("@\.\w+$@","",$destImage).".png" ); //ATUALIZA NA SQL O CAMINHO $requete25 = mysql_query("UPDATE users SET pics='evo/$imgid.png' WHERE id_membre='$id'") or die(mysql_error()); echo"Concluido, sua imagem foi carregada com sucesso."; } //ESVAZIA A MEMÓRIA USADA imagedestroy($source); imagedestroy($dest); return preg_replace("@\.\w+$@","",basename($destImage) ).".$mimeImg"; } } //FIM ?>vlw.. :lol: ;) Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 RodrigoGomes Postado Janeiro 30, 2007 Autor Denunciar Share Postado Janeiro 30, 2007 melhorei mais um pouco o script, agora ele detecta se o usuário selecionou alguma imagem.. ;) bom proveito..<?php $mysql_host = 'localhost'; $mysql_user = 'xxx'; $mysql_password ='xxx'; $mysql_base = 'xxx; mysql_connect("$mysql_host","$mysql_user","$mysql_password"); mysql_select_db("$mysql_base"); if($_POST['dir'] != ok ){ echo"<form method=\"POST\" enctype=\"multipart/form-data\" action=\"upload.php\"> <input type=hidden name=dir value=ok> <input type=\"file\" name=\"file\" size=\"20\"><br> <input type=\"submit\" value=\"Submeter\"> </form>"; } $maxLarg = "110"; // Max Width $maxAlt = "110"; // Max Height $maxTam = "400"; // Max Size (Kbytes); $mimeImg = "png"; // Mime Type to save imagefiles $taille = 40; $lettres = "abcdefghijklmnopqrstuvwxyz0123456789"; srand(time()); for ($i=0;$i<$taille;$i++) { $sessid.=substr($lettres,(rand()%(strlen($lettres))),1); $imgid=substr("$sessid", 0, 60); } $dir = "fotos/$imgid"; treat_image($_FILES['file']['tmp_name'],$dir,$id,$imgid); function treat_image($filename,$destImage=null,$id,$imgid){ if (strlen($filename) == 0){ if($_POST['dir'] == ok ){ echo"Você não selecionou uma imagem."; } } else { if (!is_file($filename) || is_file($destImage)) return false; if ($destImage===FALSE) $destImage=$filename; global $maxLarg; global $maxAlt; global $maxTam; global $mimeImg; list($width, $height, $type, $attr) = getimagesize($filename); $percent = min(round(($maxLarg / $width),2),round(($maxAlt/$height),2),1); $newwidth = floor($width * $percent); $newheight = floor($height * $percent); switch ($type) { case 2 : $source = imagecreatefromjpeg ($filename); break; case 1 : $source = imagecreatefromgif ($filename); break; case 3 : $source = imagecreatefrompng ($filename); break; default : $stop = true; break; } if(!eregi("^image\/(pjpeg|jpeg|png|x-png|gif)$", $_FILES['file']["type"])) { echo"Arquivo em formato inválido! A imagem deve ser jpg, jpeg, gif ou png. Envie outro arquivo"; } else { $dest = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($dest, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); switch($mimeImg){ case "png":imagepng($dest, preg_replace("@\.\w+$@","",$destImage).".png" ); $requete25 = mysql_query("UPDATE tabela SET pics='$imgid.png' WHERE id='$id'") or die(mysql_error()); echo"Concluido, sua imagem foi carregada com sucesso."; } imagedestroy($source); imagedestroy($dest); return preg_replace("@\.\w+$@","",basename($destImage) ).".$mimeImg"; } } } ?> Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 RodrigoGomes Postado Janeiro 30, 2007 Autor Denunciar Share Postado Janeiro 30, 2007 melhorei um pooookinho mais.. :P <?php $mysql_host = 'localhost'; $mysql_user = 'xxx'; $mysql_password ='xxx'; $mysql_base = 'xxx; mysql_connect("$mysql_host","$mysql_user","$mysql_password"); mysql_select_db("$mysql_base"); if($_POST['dir'] != ok ){ echo"<form method=\"POST\" enctype=\"multipart/form-data\" action=\"upload.php\"> <input type=hidden name=dir value=ok> <input type=\"file\" name=\"file\" size=\"20\"><br> <input type=\"submit\" value=\"Submeter\"> </form>"; } $maxLarg = "110"; // Max Width $maxAlt = "110"; // Max Height $maxTam = "400"; // Max Size (Kbytes); $mimeImg = "png"; // Mime Type to save imagefiles $taille = 40; $lettres = "abcdefghijklmnopqrstuvwxyz0123456789"; srand(time()); for ($i=0;$i<$taille;$i++) { $sessid.=substr($lettres,(rand()%(strlen($lettres))),1); $imgid=substr("$sessid", 0, 60); } $dir = "fotos/$imgid"; treat_image($_FILES['file']['tmp_name'],$dir,$id,$imgid); function treat_image($filename,$destImage=null,$id,$imgid){ if (strlen($filename) == 0){ if($_POST['dir'] == ok ){ echo"Você não selecionou uma imagem."; } } else { if(!eregi("^image\/(pjpeg|jpeg|png|x-png|gif)$", $_FILES['file']["type"])) { echo"Arquivo em formato inválido! A imagem deve ser jpg, jpeg, gif ou png. Envie outro arquivo"; } else { if (!is_file($filename) || is_file($destImage)) return false; if ($destImage===FALSE) $destImage=$filename; global $maxLarg; global $maxAlt; global $maxTam; global $mimeImg; list($width, $height, $type, $attr) = getimagesize($filename); $percent = min(round(($maxLarg / $width),2),round(($maxAlt/$height),2),1); $newwidth = floor($width * $percent); $newheight = floor($height * $percent); switch ($type) { case 2 : $source = imagecreatefromjpeg ($filename); break; case 1 : $source = imagecreatefromgif ($filename); break; case 3 : $source = imagecreatefrompng ($filename); break; default : $stop = true; break; } $dest = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($dest, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); switch($mimeImg){ case "png":imagepng($dest, preg_replace("@\.\w+$@","",$destImage).".png" ); $requete25 = mysql_query("UPDATE tabela SET pics='$imgid.png' WHERE id='$id'") or die(mysql_error()); echo"Concluido, sua imagem foi carregada com sucesso."; } imagedestroy($source); imagedestroy($dest); return preg_replace("@\.\w+$@","",basename($destImage) ).".$mimeImg"; } } } ?> Citar Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
RodrigoGomes
tive que renomea o fórum porque eu mesmo já havia resolvido o problema espero que os moderadores não levem isso a mal.. abaixo a minha dúvida... ;)
Link para o comentário
Compartilhar em outros sites
4 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.