← Desenvolvimento

Verificar extensão da imagem!

Lida 2647 vezes

Offline

cenourinha 
Elite
Mensagens 4094 Gostos 21
Troféus totais: 34
Trófeus: (Ver todos)
Mobile User Apple User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

Bem, eu tenho um script >> http://cenourinha.weblusa.org/ << que permite criar o codigo das noticias do Webtuga!
O que eu queria era ao inserir o link da thumbnail e da screenshot, ele detectava a extensão e depois verificava o tamanho!
Naquele eu só tenho em formato gif!

Código: [Seleccione]

$img = @imagecreatefromgif($url);
$img_height = imagesy($img);
$img_weith = imagesx($img);


ou seja, ele vai buscar informação da imagem ao link que está depositado na varivel $url e verifica a extensão!

O que eu queria era tipo isto:

Código: [Seleccione]
$img = @imagecreatefrom$ext($url);
$img_height = imagesy($img);
$img_weith = imagesx($img);


onde a varivel $ext armazenava a informação da extensão! Gif, png, jpg, bmp!

Se alguem me poder ajudar agradecia!
Offline

morpheus 
Membro
Mensagens 1199 Gostos 0
Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 1000 Posts

se já tens a variavel $ext definida, e que tal:

Código: [Seleccione]
$type='@imagecreatefrom'.$ext;
$img = $type($url);
$img_height = imagesy($img);
$img_weith = imagesx($img);
Offline

cenourinha 
Elite
Mensagens 4094 Gostos 21
Troféus totais: 34
Trófeus: (Ver todos)
Mobile User Apple User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

Nops a variavel $ext é que eu queria saber como vou buscar a extensão ao ficheiro para fazer isso que tens ai em cima!
Offline

morpheus 
Membro
Mensagens 1199 Gostos 0
Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 1000 Posts

toma lá uma maneira fácil para saber isso:

Código: [Seleccione]
$filename = "URL_DA_IMAGEM";
if (($pos = strrpos($filename, ".")) === FALSE)
  echo "Erro! Esta imagem não tem pontos???";
else {
  $ext = substr($filename, $pos + 1);
Offline

cenourinha 
Elite
Mensagens 4094 Gostos 21
Troféus totais: 34
Trófeus: (Ver todos)
Mobile User Apple User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

Código: [Seleccione]
<?php

extract
&#40;$_POST&#41;;
extract&#40;$_GET&#41;;
extract&#40;$_REQUEST&#41;;

// vamos declarar as variaveis!

$titulo $_POST['titulo'&#93;;
$pa1 $_POST['pa1'&#93;;
$screen $_POST['screen'&#93;;
$linkdown $_POST['linkdown'&#93;;
$nomedown $_POST['nomedown'&#93;;
$linkhome $_POST['linkhome'&#93;;
$nomehome $_POST['nomehome'&#93;;
$url $_REQUEST['th'&#93;;


// Vamos agora verificar os campos!


if &#40;$titulo == null or $url == null or $pa1 == null or $screen == null or $linkdown == null or $nomedown == null or $linkhome == null or nomehome == null&#41;&#123;
echo&#40;"Não foram inseridos os dados requeridos! Verifique os dados!"&#41;;
&#125;
else&#123;
$filename $_REQUEST['th'&#93;;
if &#40;&#40;$pos = strrpos&#40;$filename, "."&#41;&#41; === FALSE&#41;
  
echo "Erro! Esta imagem não tem pontos???";
else &
#123;
  
$ext substr&#40;$filename, $pos + 1&#41;;
$type='@imagecreatefrom'.$ext;
$img $type&#40;$url&#41;;
$img_height imagesy&#40;$img&#41;;
$img_weith imagesx&#40;$img&#41;;
&#125;
if &#40;$pa1 = null&#41;&#123;
echo&#40;"Precisa de ter pelo menos o primeiro parágrafo!"&#41;;
&#125;

elseif &#40;$img_height > 250 and $img_weith > 250&#41;
&#123;
echo&#40;"Tanto a altura como a largura do thumbnail são maiores que 250, o tamanho máximo é 250"&#41;;
&#125;
elseif &#40;$img_height > 250 and $img_weith < 250&#41;&#123;
echo&#40;"A altura do thumbnail é maior que 250"&#41;;
&#125;
elseif &#40;$img_height < 250 and $img_weith > 250&#41;&#123;
echo&#40;"A largura do thumbnail é maior que 250"&#41;;
&#125;
elseif &#40;$img_height > 250&#41;&#123;
echo&#40;"A altura do thumbnail é maior que 250"&#41;;
&#125;
elseif &#40;$screen = null&#41;&#123;
echo&#40;"Não foi inserido o link da screenshot!"&#41;;
&#125;
elseif &#40;$screen = null&#41;&#123;
echo&#40;"Não foi inserido o link da screenshot!"&#41;;
&#125;
elseif &#40;$linkdown = null&#41;&#123;
echo&#40;"Não foi inserido o link para download do programa!"&#41;;
&#125;
elseif &#40;$nomedown = null&#41;&#123;
echo&#40;"Não foi inserido o nome do programa!"&#41;;
&#125;
elseif &#40;$linkhome = null&#41;&#123;
echo&#40;"Não foi inserido o link da homepage!"&#41;;
&#125;
elseif &#40;$nomehome = null&#41;&#123;
echo&#40;"Não foi inserido o nome da homepage!"&#41;;
&#125;
else &#123;

// vamos agora gerar o código se os dados anteriores estiverem todos correctos!
?>


<textarea rows="30" cols="75"><p><b>
<font face="Verdana" size="1" color="#99CC00"><?php echo $_POST['titulo'&#93;; ?></font></b></p>
<p><font face="Verdana" size="1"><?php echo $_POST['pa1'&#93;; ?></font></p>
<p><font face="Verdana" size="1"><?php echo $_POST['pa2'&#93;; ?></font></p>
<p><font face="Verdana" size="1"><?php echo $_POST['pa3'&#93;; ?></font></p>
<p><b><font face="Verdana" size="1" color="#FF9900">Screenshot:</font></b></p>
<a href="<?php echo $_POST['screen'&#93;; ?>" target="_blank"><img src="<?php echo $_POST['th'&#93;; ?>" border="0" alt="Webtuga - <?php echo $_POST['titulo'&#93;; ?>"></a><p>
<b><font face="Verdana" size="1" color="#FF9900">Download:</font><font face="Verdana" size="1">
<a href="<?php echo $_POST['linkdown'&#93;; ?>"><?php echo $_POST['nomedown'&#93;; ?></a></font></b></p>
<p><b><font face="Verdana" size="1" color="#FF9900">Homepage:</font><font face="Verdana" size="1"> </font>
<font face="Verdana" size="1" color="#FF9900">
<a href="<?php echo $_POST['linkhome'&#93;; ?>"><?php echo $_POST['nomehome'&#93;; ?></a></font></b></p>
<p><b><font face="Verdana" size="1" color="#FF9900">Avaliação: </font></b></p>
<p><a href="http://www.webtuga.com"><img src="<?php echo $_POST['ava'&#93;; ?>"></a></p>
<p> </p></textarea>
<?
}
}
?>


Tenho isso e dá-me este erro:

Fatal error: Call to undefined function: @imagecreatefromgif() in /home/cenourin/public_html/resultado.php on line 32



http://cenourinha.weblusa.org/
Offline

kingless 
Membro
Mensagens 857 Gostos 0
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2 Level 1

tenta colocar essa variavel assim

Código: [Seleccione]

$type="@imagecreatefrom".$ext;


em vez de ' '  coloca " "
Offline

cenourinha 
Elite
Mensagens 4094 Gostos 21
Troféus totais: 34
Trófeus: (Ver todos)
Mobile User Apple User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

Citação de: "kingless"
tenta colocar essa variavel assim

Código: [Seleccione]

$type="@imagecreatefrom".$ext;


em vez de ' '  coloca " "


é a mesma coisa!
Offline

kingless 
Membro
Mensagens 857 Gostos 0
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2 Level 1

Não é igual!!

Exemplo:

'$var'   é diferente de   "$var"

Código: [Seleccione]

$var = "teste";
echo "$var";
echo '$var';


executa este codigo e ve o resultado!!  :wink:
Offline

cenourinha 
Elite
Mensagens 4094 Gostos 21
Troféus totais: 34
Trófeus: (Ver todos)
Mobile User Apple User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

Citação de: "kingless"
Não é igual!!

Exemplo:

'$var'   é diferente de   "$var"

Código: [Seleccione]

$var = "teste";
echo "$var";
echo '$var';


executa este codigo e ve o resultado!!  :wink:


Sim, mas deu o mesmo erro!