jaa Posted April 8, 2004 Report Share Posted April 8, 2004 Ar kaada skripta paliidziibu var panaakt, lai lapaa paraadaas visas bildes, kas ir konkreetaa direktorijaa .jpg formaataa? Link to comment Share on other sites More sharing options...
hu_ha Posted April 8, 2004 Report Share Posted April 8, 2004 nu izmanto scandir funkciju: http://lv.php.net/manual/en/function.scandir.php tev visa direktorija tiks samesta masiivaa - tad ar ereg() funkciju paarbaudi vai paplashunaajums ir jpg. tad jau peec tam tikai izrprinteeshanas vaina... Link to comment Share on other sites More sharing options...
Robis Posted April 8, 2004 Report Share Posted April 8, 2004 $dir = '/bildes/'; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (mime_content_type($file) == "image/jpeg") { echo "<img src='".$dir."/".$file."' alt='' />"; } } closedir($dh); } ! Briidinu, ka mime_content_type var arii nestraadaat, ja php versija nav jauna! Taadaa gadiijumaa savukaart ir jaalieto vai nu eregi_replace vai preg_replace un jaameklee no $file nosaukuma beigaam, kur ir punkts, liidz tam jaanolasa, vai sakriit ar "jpg" vai "jpeg". Link to comment Share on other sites More sharing options...
blackhalt Posted April 8, 2004 Report Share Posted April 8, 2004 Pieņemot, ka skripts ir iekš direktorijas kur bildes un ar security viss ir OK: <?php if($handle=opendir('.')){ while(false!==($file=readdir($handle))){ if($file!="."&&$file!=".."&&$file!='index.php'){ if(eregi('.jpg',$file)){ $size=getimagesize($file); echo"<img src=\"$file\" $size[3] alt=\"$file\"/>\n"; }}} closedir($handle); }?> Link to comment Share on other sites More sharing options...
jaa Posted April 10, 2004 Author Report Share Posted April 10, 2004 Pieņemot, ka skripts ir iekš direktorijas kur bildes un ar security viss ir OK:<?php if($handle=opendir('.')){ while(false!==($file=readdir($handle))){ if($file!="."&&$file!=".."&&$file!='index.php'){ if(eregi('.jpg',$file)){ $size=getimagesize($file); echo"<img src=\"$file\" $size[3] alt=\"$file\"/>\n"; }}} closedir($handle); }?> Shitais aizgaaja :) Link to comment Share on other sites More sharing options...
rnc Posted April 10, 2004 Report Share Posted April 10, 2004 Manupraat izmantot eregi buutu nepareizi , jo tad par jpg failu tiks uzskatiits arii lalala.jpg.txt :) Tad jau labaak izmantot substr() nolasot peedeejos triis simbolus un apskatiities vai tie ir jpg :) Link to comment Share on other sites More sharing options...
Robis Posted April 10, 2004 Report Share Posted April 10, 2004 Bet vislabaak gan tomeer buutu izmantot mime type, jo tas nepaarprotami paraadiitu, kaads ir faila tips... Personai, kas prasiiju paliidziibu, iespeejams, negaaja mime_content_type() funkcija, jo taa ir taada no svaigajaam php funkcijaam, kas bishkji vecaakaas versijaas neiet... Tachu var izmantot arii jau piemineeto substr(), tachu vispirms gan ir jaatrod, kur atrodas peedeejais "." faila nosaukumaa ar $position = strrpos($faila_nosaukums, "."); un tad $jpg=substr($faila_nosaukums, $position, 3); if ($jpg=='jpg') { ..... } Link to comment Share on other sites More sharing options...
rnc Posted April 10, 2004 Report Share Posted April 10, 2004 (edited) Es gan taa nedomaaju, es domaaju shaadi: substr($bla,-3,3); :) Edited April 10, 2004 by rnc Link to comment Share on other sites More sharing options...
Robis Posted April 10, 2004 Report Share Posted April 10, 2004 nu malacis, biju jau aizmirsis par tiem miinusiem ieksh substr() :) Link to comment Share on other sites More sharing options...
graavracis Posted April 15, 2004 Report Share Posted April 15, 2004 es paarbaudei vai faili ir jpg formaataa iesaku izmantot funkciju exif_imagetype( string filename) taapeec ka var buut ka kaads piemeeram *.doc failu paarsauc par *.jpg failu. A taa funkcija nosaka kaada formaata fials tas ir. Link to comment Share on other sites More sharing options...
рпр Posted April 15, 2004 Report Share Posted April 15, 2004 izmantoju kautko liidziigu shai, lai noteiktu tipu. ar string funkcijaam noteikti nedriikst to dariit, jo kautvai paarsaucot to par jPg buus probleemas... function FailaTips($cFails) { if (function_exists('mime_content_type')) { return mime_content_type($cFails); } $cOut = exec ("file -ib $cFails"); if (empty($cOut)) { $cOut = exec ("file -b $cFails"); if (stristr($cOut, 'jpeg image')) { $cOut = 'image/jpeg'; } elseif (stristr($cOut, 'gif image')) { $cOut = 'image/gif'; } elseif (stristr($cOut, 'png image')) { $cOut = 'image/png'; } else { $this->cKluda = _NavTips; return false; } } return $cOut; } Link to comment Share on other sites More sharing options...
Recommended Posts