how to echo banner (both flash & image)

Discussion in 'PHP' started by adsegzy, Oct 26, 2010.

  1. #1
    My members that want to advert may upload their banner advert in any of the below format jpg, gif, png & swf. Am having problem echoing out my banners. I can't echo either image or flash with a code, am only able to echo out banners in jpg, gif and png with the below code;
    <?php
    $getad=mysql_query("SELECT * FROM $table_name ORDER BY RAND() LIMIT 1");
    while($rows=mysql_fetch_array($getad)){
    $banner=$rows[banner];
    }
    
    echo "<img src='../$banner_folder/$banner'>";
    ?>
    PHP:
    but it doesn't work for flash banners. am only able to echo flash banner with the below code

    <?php
    $imglist='';
    $img_folder = "images/";
    mt_srand((double)microtime()*1000);
    $imgs = dir($img_folder);
    while ($file  = $imgs->read()) {
    if (eregi("swf", $file)) $imglist .= "$file "; }
    closedir($imgs->handle);
    $imglist = explode(" ", $imglist);
    $no = sizeof($imglist)-2;
    $random = mt_rand(0, $no);
    $image = $imglist[$random];
    echo '<embed src="'.$img_folder.$image.'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="100" height="100"></embed>';
    ?>
    PHP:
    But i need a code that can display the banner irrespective of its format. pls help.
     
    adsegzy, Oct 26, 2010 IP
  2. reli4nt

    reli4nt Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are images and flash stored separately? You need different html for each so your php needs to know how to distinguish one from the other. You could try something like:
    
    if (substr($banner,-1,3) == "swf") { 
    echo '<embed...'; //fill in the rest
    } else {
    echo '<img...'; //fill in the rest
    }
    PHP:
    This would check the extension for the banner and echo the appropriate code.
     
    reli4nt, Oct 27, 2010 IP