Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    90
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Cant get images to show

    I have compliled this code to do 2 things, rotate images and open a download from the query string, the download starts but no images display - php below

    PHP Code:
    <?php

    $filename 
    $_GET['filename1'];

    // required for IE, otherwise Content-disposition is ignored
    if(ini_get('zlib.output_compression'))
      
    ini_set('zlib.output_compression''Off');

    // addition by Jorg Weske
    $file_extension strtolower(substr(strrchr($filename,"."),1));

    if( 
    $filename == "" )
    {
    $downloaderror "No file to download specified";
      exit;
    } elseif ( ! 
    file_exists$filename ) )
    {
    $downloaderror "File not found";
      exit;
    };
    switch( 
    $file_extension )
    {
      case 
    "pdf"$ctype="application/pdf"; break;
      case 
    "exe"$ctype="application/octet-stream"; break;
      case 
    "zip"$ctype="application/zip"; break;
      case 
    "doc"$ctype="application/msword"; break;
      case 
    "xls"$ctype="application/vnd.ms-excel"; break;
      case 
    "ppt"$ctype="application/vnd.ms-powerpoint"; break;
      case 
    "gif"$ctype="image/gif"; break;
      case 
    "png"$ctype="image/png"; break;
      case 
    "jpeg":
      case 
    "jpg"$ctype="image/jpg"; break;
      default: 
    $ctype="application/force-download";
    }
    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers
    header("Content-Type: $ctype");
    // change, added quotes to allow spaces in filenames, by Rajkumar Singh
    header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($filename));
    readfile("$filename");
    exit();

    ?>
    <?php
    // Random Image With Link PHP Script
    // Butterfly Media Romania Blog
    // http://blog.butterflymedia.ro/
    //
    // Usage:
    //
    // Save this file as ads.php and use the include function to call it inside your web site

    function display_random_img($array) {
        
    $key rand(count($array) -1);
        
    $link_url $array[$key]['url'];
        
    $alt_tag $array[$key]['alt'];
        
    $random_img_url $array[$key]['img_url'];
        list(
    $img_width$img_height) = getimagesize($random_img_url);
        return 
    "<a href=\"$link_url\"><img src=\"$random_img_url\" width=\"$img_width\" height=\"$img_height\" alt=\"$alt_tag\" /></a>";
    }

    // Edit the following values accordingly
    $ads_array = array(
        array(
            
    'url' => 'http://www.urbanfmtv.com/',
            
    'alt' => 'Urban Affair @ Camden Rock 27th March 2009 Event',
            
    'img_url' => 'flyers/urbanaffairmarch272009.jpg'
        
    ),
        array(
            
    'url' => 'http://www.urbanfmtv.com/',
            
    'alt' => 'Urban Affair @ Camden Rock 27th March 2009 Event',
            
    'img_url' => 'flyers/urbanaffairmarch272009back.jpg'
        
    ),
        array(
            
    'url' => 'http://www.enticeparties.com/',
            
    'alt' => 'Check out the next Entice Parties event',
            
    'img_url' => 'flyers/enticebabalou.jpg'
        
    )
    );
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>dj-promo.co.uk - Downloading file..</title>
    <script type="text/javascript"><!--

    function getRefToDivMod( divID, oDoc ) {
        if( !oDoc ) { oDoc = document; }
        if( document.layers ) {
            if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
                for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
                    y = getRefToDivNest(divID,oDoc.layers[x].document); }
                return y; } }
        if( document.getElementById ) { return oDoc.getElementById(divID); }
        if( document.all ) { return oDoc.all[divID]; }
        return oDoc[divID];
    }

    function resizeWinTo( idOfDiv ) {
        var oH = getRefToDivMod( idOfDiv ); if( !oH ) { return false; }
        var x = window; x.resizeTo( screen.availWidth, screen.availWidth );
        var oW = oH.clip ? oH.clip.width : oH.offsetWidth;
        var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
        x.resizeTo( oW + 200, oH + 200 );
        var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
        if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }
        else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
        else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
        if( window.opera && !document.childNodes ) { myW += 16; }
        //second sample, as the table may have resized
        var oH2 = getRefToDivMod( idOfDiv );
        var oW2 = oH2.clip ? oH2.clip.width : oH2.offsetWidth;
        var oH2 = oH2.clip ? oH2.clip.height : oH2.offsetHeight;
        x.resizeTo( oW2 + ( ( oW + 200 ) - myW ), oH2 + ( (oH + 200 ) - myH ) );
    }

    //-->
    </script>

    </head>

    <body onload="resizeWinTo('mydiv')"; style="padding:0;margin:0;" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
    <div style="position:absolute;left:0px;top:0px;" id="mydiv">
    <?php echo display_random_img($ads_array); ?>
    <b><?php echo $downloaderror ?></b>
    </div>
    </body>
    </html>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Does the <img> tag get properly created? You can see if it does by viewing the page source.

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    90
    Thanks
    5
    Thanked 0 Times in 0 Posts
    The route of the problem I beleive is in the force download part as this I'm sure does something to over ride the page from displaying as it wants to load the file to download, its more or less just getting round that but i'm beginning to believe this is not possibe, I might be wrong any ideas any one?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Yeah I think you're right. You are sending headers that says the document is a download (basically) so it discards everything else.

    You may want to look into sending headers using "multi-part" as the content disposition, which looks like it allows you to mix text/html and a prompt for download. Google for a while; if you can't find how to do it I'll google too.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •