Lokomotive Posted March 23, 2004 Report Share Posted March 23, 2004 (edited) Nevarēju atrast random funkciju, kas piemēram pie lapas ielādes paņemtu kādu bildi no direktorijā esošajām. Noskanēt direktoriju var gan ar scandir, gan ar readdir funkciju: <?php if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "$file\n"; } } closedir($handle); } ?> Taču kā lai izveido random funkciju? Edited March 23, 2004 by Lokomotive Link to comment Share on other sites More sharing options...
bubu Posted March 23, 2004 Report Share Posted March 23, 2004 elementaari: ielasi visas bildes masiivaa un izveelies peec random indeksa :) Link to comment Share on other sites More sharing options...
rnc Posted March 23, 2004 Report Share Posted March 23, 2004 (edited) scandir() un readdir() imho nav viens un tas pats. scandir() visus direktorijas elementus ievelk masiiva, bet shii f-ja laikam ir tikai no PHP 5. Ar scandir vareetu buut eerti :) <?php $mas = scandir('/direktorija'); foreach ($mas as $m) if ($m != "." && $m !="..") $mas[] = $m; // nodzeesham liekos punktus echo '<img src="'.$mas[rand(0,count($mas))].'">'; ?> ?> Rakstiju no galvas, nav kur notesteet, negaranteeju ka darbosies ;) Edited March 23, 2004 by rnc Link to comment Share on other sites More sharing options...
Lokomotive Posted March 23, 2004 Author Report Share Posted March 23, 2004 (edited) Paldies rnc, es hostējos pie Latneta, tāpēc scandir man ir pieejams. Vienīgais mīnuss Latnetam ir tas, ka par Mysql ir jāmaksā papildus 10Ls mēnesī - tāpēc nevaru izmantot datubāzes un ir jāmokās ar .txt failiem :( Edited March 23, 2004 by Lokomotive Link to comment Share on other sites More sharing options...
des Posted March 25, 2004 Report Share Posted March 25, 2004 Taapeec jau Latnets pamatiigi sux... 10Ls par mysql.... VAAAX!!! Link to comment Share on other sites More sharing options...
rnc Posted March 25, 2004 Report Share Posted March 25, 2004 Nu bet, ar *.txt arii daudz ko var sameistarot :) Link to comment Share on other sites More sharing options...
Gacha Posted March 25, 2004 Report Share Posted March 25, 2004 Nu man piemeram agrāk gustbuks stradaja uz text failiem. Bet galvenais bija tas, ka tajaa failaa saglabaajaas ne tikai texts, bet arii visi html tagi kas bija tam postam un tas bija diezgan daudz. Kopumaa man bija savaakushies kaadi paaris simti postu - un es neteiktu, ka tas viss vilktos. Viss gaaja normaali, tapeec es domaaju, ka zinju sisteemu lapai mieriigi var taisiit. Uz 2 gadiem derees mieriigi! Link to comment Share on other sites More sharing options...
rnc Posted March 25, 2004 Report Share Posted March 25, 2004 (edited) Var jau visaadi sataisiit, njemsim katram meenesim savs fails, vai tml ;) Lai nav jaaiet cauri failam kuraa ir septinjus gadus vecas zinjas :) P.S. Gacha, apsveicu tevi ar tavu 300. postu! Edited March 25, 2004 by rnc Link to comment Share on other sites More sharing options...
n0r3k Posted March 29, 2004 Report Share Posted March 29, 2004 ja esi pa slinku, lai pats iemaaciitos, tad njem tev jau gatavs, tikai neaizmirsti papeetiit un images/ direktorijaa sabaaazt images =] <? mt_srand((double)microtime()*1000000); $imgs = dir('images'); while ($file = $imgs->read()) { if (eregi("gif", $file) || eregi("jpg", $file)) { $imglist .= "$file "; } } closedir($imgs->handle); $imglist = explode(" ", $imglist); $a = sizeof($imglist)-2; $random = mt_rand(0, $a); $image = $imglist[$random]; $content = "<br><center><img src=\"images/$image\" border=\"0\"><br><br></center>"; echo $content; ?> Link to comment Share on other sites More sharing options...
Chickenz Posted April 3, 2004 Report Share Posted April 3, 2004 Sorry bet to var vienkāršāk uztaisīt - visas bildes ir (1.bmp, 2.bmp, 3.bmp) <?$bilde=rand(1,100); echo "<img src="images/$bilde.bmp">";?> vai kaut kā tā! vienīgi ja visas bildes ir viena formāta! :) Link to comment Share on other sites More sharing options...
Gacha Posted April 3, 2004 Report Share Posted April 3, 2004 Bet tad jau uploudojot bildes vinjas vajag nummureet - tas nebuut nav eerti. Bet var uztaisiit scriptinju, kas pirms uplouda izskenee diru cik tur ir, ja ir 100 tad vinjsh sho bildi nosauc 101.jpg B) Link to comment Share on other sites More sharing options...
Chickenz Posted April 4, 2004 Report Share Posted April 4, 2004 nu jaa, tachu es paraadiiju domu taalaakais ir vinja pasha zinjaa Link to comment Share on other sites More sharing options...
Ugga Posted April 5, 2004 Report Share Posted April 5, 2004 nu ja Link to comment Share on other sites More sharing options...
Recommended Posts