22 Eylül 2010 Çarşamba

php randomize arkaplan resmini değiştiren kod

randomize çıkmasını istediğimiz resimlerimizi ve bu random.php dosyamızı aynı klasör altına koyuyor ve arkaplan resmimizi çektiğimiz,css dosyamıza küçük bir değişiklik yapıyoruz.

background: url(bg/random.php); 

-----------------------random.php dosyası--------------------------------------- 
$extList = array();$extList['jpg'] = 'image/jpeg';$extList['jpeg'] = 'image/jpeg';$extList['png'] = 'image/png';
$img = null;
$fileList = array();$handle = opendir('./');
while (
false !== ($file = readdir($handle))) {
   
$fileInfo = pathinfo($file);
    if (isset(
$extList[strtolower($fileInfo['extension'])])) {
       
$fileList[] = $file;
    }
}
closedir($handle);

if (
count($fileList) > 0) {
   
$imgNum = time() % count($fileList);
   
$img = $folder.$fileList[$imgNum];
}

if (
$img!=null) {
   
$imgInfo = pathinfo($img);
   
$contentType = 'Content-type: '.$extList[$imgInfo['extension']];
   
header($contentType);
   
readfile($img);
}
?>


artık sayfamız her yenilendiğinde resimlerimiz değişiyor.Yeni resim eklemek ise çok kolay sadece resmi php dosyasının bulunduğu klasöre eklemek

Hiç yorum yok:

Yorum Gönder