Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal a ideia desse código é mostrar todas as imagens de de um diretório (qualquer), mas está mostrando apenas uma http://forum.imasters.com.br/public/style_emoticons/default/hug.gif e não consigo indentificar onde está o erro, pq pela lógica acho q o codigo está correto, a naum ser q tenha algo q eu não sei, pois sou quase leigo nos trabalhos com imagens... veja o código:
PHP
[*]<?
[*]$dir = "..";
[*]if(substr($dir,-1) != "/" || substr($dir,-1) != "\\"){
[*] $dir .= "/";
[*]}
[*]if (is_dir($dir)) {
[*] if ($dh = opendir($dir)){
[*] while (($file = readdir($dh)) !== false){
[*] if($file != "." || $file != ".."){
[*] if(eregi(".gif",$file) || eregi(".png",$file) || eregi(".jpg",$file)){
[*] $ext = strtolower(end(explode(".",$file)));
[*] if($ext == "jpg" || $ext == "jpeg"){
[*] $img = imagecreatefromjpeg($dir.$file);
[*] }elseif($ext == "png") {
[*] $img = imagecreatefrompng($dir.$file);
[*] }elseif($ext == "gif"){
[*] $img = imagecreatefromgif($dir.$file);
[*] }
[*] if($img){
[*] $width = imagesx($img);
[*] $height = imagesy($img);
[*] $scale = min(80/$width, 80/$height);
[*] if($scale < 1){
[*] $new_width = floor($scale*$width);
[*] $new_height = floor($scale*$height);
[*] $tmp_img = imagecreatetruecolor($new_width, $new_height);
[*] imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
[*] imagedestroy($img);
[*] $img = $tmp_img;
[*] }
[*] }else{
[*] $img = imagecreate(80, 80);
[*] imagecolorallocate($img,204,204,204);
[*] $c = imagecolorallocate($img,153,153,153);
[*] $c1 = imagecolorallocate($img,0,0,0);
[*] imageline($img,0,0,80,80,$c);
[*] imageline($img,80,0,0,80,$c);
[*] imagestring($img, 2, 12, 55, 'erro ao carregar imagem',$c1 );
[*] header('Content-type: image/jpeg');
[*] imagejpeg($img);
[*] }
[*] if($ext == "jpg" || $ext == "jpeg"){
[*] imagejpeg($img)."<br>";
[*] }elseif($ext == "png"){
[*] imagepng($img)."<br>";
[*] }elseif($ext == "gif"){
[*] imagegif($img)."<br>";
[*] }
[*]//Linha usada para mostrar apenas o nome dos arquivos (Para Teste)
[*]// echo "$file<br>";
[*] }
[*] }
[*] }
[*] closedir($dh);
[*] }
[*]}else{
[*] echo "'$dir' não é um diretório inválido";
[*]}
[*]?>
Carregando comentários...