Results 1 to 4 of 4

Thread: PHP Imageviewer preventing file extension printout

  1. #1
    Join Date
    Nov 2007
    Posts
    39
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default PHP Imageviewer preventing file extension printout

    Hi, I'm using Imageviewer by Trent Williams
    How would I get rid of the extention of the file from printing out?

    I'm hoping to be able to explain the image in its file name but having, "explosion in a alley.jpg"
    Doesnt really look that good.
    I'll be using it to display funny animated gifs, and pics in my Bittorrent flash humour site.
    Any help would be appreciated.

    Heres the code:
    PHP Code:
    <?php

    //=========================================
    //
    // Author: Trent Williams
    // Date: 19 Aug 2005


    // EXPLAINATION
    //
    // A simply script to drop in any dir to display next prev buttons and current image for all your images in that dir with extentions you allow
    // Uses id parameter to know what image to show next else it will show first image
    // Also a number list at bottom page to go to any image, alt text displays image name

    // change the colours in the styles in the html body






    //which dir
    $d dir(".");

    //read thru and
    while (false !== ($entry $d->read())) {
    //allow extensions here
    //|| preg_match("/(\.bmp$)/i", $entry)
    //|| preg_match("/(\.jpeg$)/i", $entry)

    if (preg_match("/(\.gif$)/i"$entry) || preg_match("/(\.png$)/i"$entry) || preg_match("/(\.jpg$)/i"$entry)){
    $pics[] = $entry;
    }

    }
    $d->close();


    //================
    //total images count
    $numPics count($pics);



    //================
    //picture in array to show on this page
    $thispic 0;
    if (
    is_numeric($_GET['id'])){
    $thispic $_GET['id'];
    }
    $thispicDisplay $thispic 1;



    //================
    //img tag for current image
    $thisImage '<img src="' $pics[$thispic] . '" alt="' $pics[$thispic] . '" />';



    //======================
    // START set thumbnails on or off

    //comment this section out if you don't want thumbs to show at all

    $showThumbs 5;//number of thums to show
    $thumbsList '';
    $thumburl '';
    if (
    $_GET['thumb'] == 'yes'){
    //read thumb param to url if exists
    $thumburl '&amp;thumb=yes';

    for (
    $i=0;$i<$showThumbs;$i++){
    if (
    $thispic $i $numPics){
    $currThumb $thispic $i 1;
    $thumbsList .= '<a href="' $_SERVER['PHP_SELF'] . '?id=' $currThumb $thumburl '" title="' $pics[$currThumb] . '"><img src="' $pics[$currThumb] . '" alt="' $pics[$currThumb] . '" height="100" width="100" border="0" /></a>&nbsp;&nbsp;&nbsp;';
    }
    }
    $onOff ='<a class="thumbs" href="' $_SERVER['PHP_SELF'] . '?id=' $thispic '">Turn Thumbnails Off</a>';
    } else {
    $onOff ='<a class="thumbs" href="' $_SERVER['PHP_SELF'] . '?id=' $thispic '&amp;thumb=yes">Turn Thumbnails On</a>';
    }

    // END set thumbnails on or off





    //prev button

    $prevurl ' <span class="highlighted">First Picture</span>';
    if (
    $thispic 0){
    $prev $thispic 1;
    $prevurl '<a href="' $_SERVER['PHP_SELF'] . '?id=' $prev $thumburl '" title="' $pics[$prev] . '">Previous picture</a>';
    }




    //next button

    $nexturl ' <span class="highlighted">Last Picture</span>';
    if (
    $thispic < ($numPics 1)){
    $next $thispic 1;
    $nexturl '<a href="' $_SERVER['PHP_SELF'] . '?id=' $next $thumburl '" title="' $pics[$next] .'">Next picture</a>';
    }



    //=======================
    // string of all pics url's
    $urlarray '';
    for (
    $i=0;$i<count($pics);$i++){
    //highlign pic you are on
    $j $i 1;

    if (
    $i != $thispic){

    $urlarray .= '<a href="' $_SERVER['PHP_SELF'] . '?id=' $i $thumburl .'" title="' $pics[$i] . '">' $j .'</a> ';
    } else {
    $urlarray .= ' <span class="highlighted">' $j '</span> ';
    }


    }







    ?>
    <?php 
    echo '<?xml version="1.0" encoding="iso-8859-1"?>' "\n"?>
    <!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>
    <title><?=$pics[$thispic]?></title>
    <meta name="Author" content="Trent Williams" />
    <style type="text/css">
    *{margin:0px;}
    html, body{color:#000; background-color:#000;}
    .borders {background:#A8E4FF; border:2px solid #808080; padding:10px; width:100%; float:left; font-family:arial, helvetica, sans-serif; font-size:85%;}
    .content {padding:10;}
    a{color:#000;text-decoration:none; font-weight:bold;}
    a:hover{text-decoration:underline;}
    .highlighted {color:#DF1C11; font-weight:bold;}

    a.thumbs {color:#DBDE5C;text-decoration:none; font-weight:bold;}

    </style>
    </head>

    <body>


    <table cellpadding="0" cellspacing="10" border="0">
    <tr>
    <td>

    <div class="borders"><?=$prevurl?>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<?=$nexturl?>&nbsp;&nbsp;&nbsp;Picture number: <strong><?=$thispicDisplay?></strong> &nbsp;&nbsp;Picture name: <strong><?=$pics[$thispic]?></strong></div>




    <div class="content"><center><?=$thisImage?></center></div>

    <div class="content"><?=$onOff?><center><?=$thumbsList?></center></div>

    <div class="borders"><?=$urlarray?></div>


    </td>
    </tr>
    </table>


    </body>
    </html>

  2. #2
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Code:
    $name = substr($pics[$thispic], 0, strrpos($pics[$thispic], '.'));
    strrpos($pics[$thispic], '.') finds the first dot in the filename starting from the end (i.e., the last dot). substr($pics[$thispic], 0, strrpos($pics[$thispic], '.')) takes the segment of the string from the beginning through the character just before the dot.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  3. #3
    Join Date
    Nov 2007
    Posts
    39
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    So I can safely delete that?

  4. #4
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Huh? I didn't tell you to delete anything; that line of code will find the name in "name.ext" and assign it to name. Put it in your code and output name rather than $pics[$thispic] (unless you want the URL).
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

Bookmarks

Posting Permissions

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