Snukzz Posted February 7, 2005 Report Share Posted February 7, 2005 Gribeeju uzciniit, lai skripc nolasa mapes saturu un tad randomaa izvada vienu bildi! <? error_reporting(E_ALL); $thumbstring = ''; $file_dir="Bildz"; $f_type=".jpg"; $dir=opendir($file_dir); while ($file=readdir($dir)) { if ($file != "." && $file != "..") { $extension=substr($file,-6); if($extension == $f_type) { $thumbstring .= "$file|"; } } } srand((double)microtime()*1000000); $arry_txt = explode("|" , $thumbstring); echo "<img src=\"".$file_dir."/".$arry_txt[rand(0, sizeof($arry_txt) -1)]."\">"; ?> Bet shis man izvada tikai mapi (<img src="trallallaa.lv/Bildz">) - failus nenolasot! a kaa ta taa??? Link to comment Share on other sites More sharing options...
рпр Posted February 7, 2005 Report Share Posted February 7, 2005 $extension=substr($file,-6); vai tad ".jpg" ir 6 simboli? un kas notiek ja nav nevienas bildes? Link to comment Share on other sites More sharing options...
Snukzz Posted February 7, 2005 Author Report Share Posted February 7, 2005 $extension=substr($file,-6); vai tad ".jpg" ir 6 simboli? un kas notiek ja nav nevienas bildes? 13445[/snapback] Atvainojos... vecums un aklums naak roku rokaa!:))) Link to comment Share on other sites More sharing options...
Snukzz Posted February 7, 2005 Author Report Share Posted February 7, 2005 Pag,... bet kaaa lai es vinjam lieku izveeleeties tikai tos failus kuriem saakumaa ir Th_ ??? Link to comment Share on other sites More sharing options...
Venom Posted February 7, 2005 Report Share Posted February 7, 2005 substr($filename,0,3)=='Th_'? Link to comment Share on other sites More sharing options...
рпр Posted February 7, 2005 Report Share Posted February 7, 2005 tev jau te labaak izmantot regulaaraas ekspresijas kautko uz shito shniti: preg_mathc('#^Th.+\.jpg$#', $file); Link to comment Share on other sites More sharing options...
Snukzz Posted February 7, 2005 Author Report Share Posted February 7, 2005 Nu jaa.... labi megjinaasim kaut kaa taa! Link to comment Share on other sites More sharing options...
Venom Posted February 7, 2005 Report Share Posted February 7, 2005 tad jau labāk uz #^th_.+\.(jpg|jpeg|gif|png)#i pusi Link to comment Share on other sites More sharing options...
Roze Posted February 7, 2005 Report Share Posted February 7, 2005 Vai nav smukāk?: <? $image = glob("path/Th_{*.gif,*.jpg,*.png}", GLOB_BRACE); echo '<img src="'.$image[array_rand($image)].'"/>'; ?> .. performance hvz Link to comment Share on other sites More sharing options...
parrymason Posted March 20, 2005 Report Share Posted March 20, 2005 .. performance hvz 13480[/snapback] Jā, performance tiešām... Man izmeta erroru "Apache has encountered a problem and needs to close". Link to comment Share on other sites More sharing options...
Roze Posted March 21, 2005 Report Share Posted March 21, 2005 Jā, performance tiešām... Man izmeta erroru "Apache has encountered a problem and needs to close". 15236[/snapback] Ganjauka vecs PHP. It's also worth noting that when using the GLOB_BRACE flag in any version of PHP prior to 4.3.4, PHP will crash if no matches are found. Upgrade! Link to comment Share on other sites More sharing options...
mazaisDeagle Posted March 23, 2005 Report Share Posted March 23, 2005 taatad tur jaliek ir skaitliitis 4 , 6 vietaa ja grib .jpg .bmp .gif .png failus.. laikam tie arii ira visi.. es nez! karochi shitais scripts ira labais man patiik aizgaja! Link to comment Share on other sites More sharing options...
Osiris Posted March 23, 2005 Report Share Posted March 23, 2005 Nolasi visus Direktorijas iekšas masīvā (array). Dabuj JPG failu nosaukumus ar string f-jam palīdzību, $count=count($kas_palicis) ). Pēc tam $random=(rnd(0,$kas_palicis)) vai kā tur bija (var būt kļudijos). Un izvelk no masīva Nr. "$random". Talāk pats zini. Es pats glabāju failu nosaukumus DBē - tā vieglāk operēt, ja failu mainīsi ar rokām, neviss ar web-interfeisa palīdzību. myPHPAdmin rulez! Es pats necienu rutīnu (ķipa array, līdz galam to nevaru apgūt), bet izskatas par variantu. Veiksmi! Link to comment Share on other sites More sharing options...
Delfins Posted March 24, 2005 Report Share Posted March 24, 2005 nesaprotu kāpēc visu laiku ir jālasa direktorija... taču noindeksē un pēc tam ārdies. $files = unserialize( file_get_contents('files.idx') ); if ( is_array($files) ) { $file = $files[rand(0,count($files))]; } Link to comment Share on other sites More sharing options...
bubu Posted March 24, 2005 Report Share Posted March 24, 2005 Kā var neapgūt array? Masīvs tak ir viena no nepieciešamākajām un fundamentālākajām datu struktūrām programmēšanā. Link to comment Share on other sites More sharing options...
Recommended Posts