Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá pessoal!
Estou com uma dificudade aqui.
Olher este codico.
$acao="enviar";
$tipo=0;
$arquivos[]=$_POST['arquivos[]'];
$post_title=$_POST['post_title'];
$coment=$_POST['coment'];
$musicas= htmlspecialchars($_POST["musicas"]);
$tamanho = getimagesize($_FILES['arquivos']['tmp_name'][0]);
$type = $_FILES['arquivos']['type'][0];
if ($type != "image/pjpeg" && $type != "image/pjpg" && $type != "image/pjpe" && $type != "image/gif") { header("location: flog.php?floguito=enviar&erro=Arquivo Inválido"); exit(); }
if ($tamanho[0] <= 500) { $largura = $tamanho[0]; } else { $largura = 500; }
$datada=strftime("%Y%m%d%H%M%S");
function criar_thumb($origem, $datada, $destino, $largura='100', $altura='75',$pre='',$formato='JPEG') {
switch($formato)
{
case 'JPEG':
$tn_formato = 'jpg';
break;
case 'PNG':
$tn_formato = 'png';
break;
}
$ext = split("[/\\.]",strtolower($origem));
$n = count($ext)-1;
$ext = $ext[$n];
$arr = split("[/\\]",$origem);
$n = count($arr)-1;
$arra = explode('.',$arr[$n]);
$n2 = count($arra)-1;
$destino = $destino.$datada.'.'.$tn_formato;
if ($ext == 'jpg' || $ext == 'jpeg'){
$im = imagecreatefromjpeg($origem);
}elseif($ext == 'png'){
$im = imagecreatefrompng($origem);
}elseif($ext == 'gif'){
$im = @ImageCreateFromGIF($origem);
}
$w = imagesx($im);
$h = imagesy($im);
if ($w > $h)
{
$nw = $largura;
$nh = $altura;
//$nh = ($h * $largura)/$w;
}else{
$nw = $largura;
$nh = $altura;
//$nw = ($w * $largura)/$h;
}
if(function_exists('imagecopyresampled'))
{
if(function_exists('imageCreateTrueColor'))
{
$ni = imageCreateTrueColor($nw,$nh);
}else{
$ni = imagecreate($nw,$nh);
}
if(!@imagecopyresampled($ni,$im,0,0,0,0,$nw,$nh,$w,$h))
{
imagecopyresized($ni,$im,0,0,0,0,$nw,$nh,$w,$h);
}
}else{
$ni = imagecreate($nw,$nh);
imagecopyresized($ni,$im,0,0,0,0,$nw,$nh,$w,$h);
}
//if($tn_formato=='jpg'){
imagejpeg($ni,$destino,60);
//}elseif($tn_formato=='png'){
// imagepng($ni,$destino);
//}
}
function criar_foto($origem, $datada, $destino, $largura, $pre='',$formato='JPEG') {
switch($formato)
{
case 'JPEG':
$tn_formato = 'jpg';
break;
case 'PNG':
$tn_formato = 'png';
break;
}
$ext = split("[/\\.]",strtolower($origem));
$n = count($ext)-1;
$ext = $ext[$n];
$arr = split("[/\\]",$origem);
$n = count($arr)-1;
$arra = explode('.',$arr[$n]);
$n2 = count($arra)-1;
//$tn_name = $datada; //str_replace('.'.$arra[$n2],'',$arr[$n]);
$destino = $destino.$datada.'.'.$tn_formato;
if ($ext == 'jpg' || $ext == 'jpeg'){
$im = imagecreatefromjpeg($origem);
}elseif($ext == 'png'){
$im = imagecreatefrompng($origem);
}elseif($ext == 'gif'){
$im = @ImageCreateFromGIF($origem);
}
$w = imagesx($im);
$h = imagesy($im);
if ($w > $h)
{
$nw = $largura;
$nh = ($h * $largura)/$w;
}else{
$nh = $largura;
$nw = ($w * $largura)/$h;
}
if(function_exists('imagecopyresampled'))
{
if(function_exists('imageCreateTrueColor'))
{
$ni = imageCreateTrueColor($nw,$nh);
}else{
$ni = imagecreate($nw,$nh);
}
if(!@imagecopyresampled($ni,$im,0,0,0,0,$nw,$nh,$w,$h))
{
imagecopyresized($ni,$im,0,0,0,0,$nw,$nh,$w,$h);
}
}else{
$ni = imagecreate($nw,$nh);
imagecopyresized($ni,$im,0,0,0,0,$nw,$nh,$w,$h);
}
//if($tn_formato=='jpg'){
imagejpeg($ni,$destino,100);
//}elseif($tn_formato=='png'){
// imagepng($ni,$destino);
//}
}
Ele so ler JPG
Não Grava outras estenções como faço para arruma?
Alguem pode ajuda eu?
Agora quando tento posta arquivos
GIF ou outro da isto
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 137
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'temp.jpg' is not a valid JPEG file in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 137
Warning: imagesx(): supplied argument is not a valid Image resource in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 143
Warning: imagesy(): supplied argument is not a valid Image resource in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 144
Warning: Division by zero in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 151
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 157
Warning: imagecopyresized(): supplied argument is not a valid Image resource in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 163
Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 170
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 62
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'temp.jpg' is not a valid JPEG file in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 62
Warning: imagesx(): supplied argument is not a valid Image resource in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 68
Warning: imagesy(): supplied argument is not a valid Image resource in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 69
Warning: imagecopyresized(): supplied argument is not a valid Image resource in /home/flogmix/webapps/ROOT/enviar_gravar.php on line 90
Sera o q esta de errado?
Não estudei seu código a fundo, só passei os olhos, mas vão umas sugestões e comentários. :P
Em vários momentos você atribui JPEG à uma variável, depois pergunta se é JPEG ou PNG. :blink:
Aqui, por exemplo:
Se você faz isso:$formato='JPEG'Não tem porque perguntar qual o valor, pois vai ser sempre JPEG.
Uma sugestão, que não sei se vai fazer alguma diferença, mas eu uso assim.
Nessa parte:
if ($type != "image/pjpeg" && $type != "image/pjpg" && $type != "image/pjpe" && $type != "image/gif")Separe as validações com parênteses.
if (($type != "image/pjpeg") && ($type != "image/pjpg") && ($type != "image/pjpe") && ($type != "image/gif"))
Espero ter ajudado.