www.webdeveloper.com
Results 1 to 4 of 4

Thread: Getting file name of image

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Posts
    112

    Getting file name of image

    I have a slideshow going and what im trying to do is display the filename of the current image that is showing. How would I do this in php?
    Thanks!!

  2. #2
    Join Date
    Jan 2007
    Posts
    187
    what are you using the display the slideshow? Whatever it is, you need the filename to be able to display the picture. That means your script knows the filename. Just output it..

  3. #3
    Join Date
    Aug 2006
    Posts
    112
    This is what im using
    Code:
    <?php
    $dh = new DirectoryIterator( "pics" );
    
    $files = array();
    foreach( $dh as $file)
    {
    	if ( preg_match("/[.]jpg$/", $file)) $files []= "$file";
    }
    ?>
    
    
    <style>
    body		{ background: Black;}
    #thumbnails { height: 140px; width: 100%; overflow: auto;}
    #pic		{ text-align: center; height: 400px; padding: 20px;}
    </style>
    <script>
    var image_list = [
    <?php $first = true; foreach( $files as $image) { ?>
    <?php echo ($first ? "" : ", "); ?> "<?php echo ($image); ?>"
    <?php $first = false;}?>
    ];
    
    var curimage = 0;
    
    function switchimg( ind )
    {
    	var image = image_list[ind];
    	var obj = document.getElementById( "selimg" );
    	obj.src = "scale.php?image="+image+"&y=400";
    	curimage = ind;
    }
    
    function nextimage()
    {
    	curimage++;
    	if ( curimage >= image_list.length ) curimage = 0;
    	switchimg( curimage );
    }
    
    
    window.setInterval( "nextimage()", 10000 );
    </script>
    
    <table width="100%">
    <tr>
    <?php $ind = 0; foreach ($files as $image) { ?>
    <td width="160" nowrap align="center">
    <a href="javascript:switchimg( <?php echo ($ind); ?> )">
    <img height="100" src="scale.php?image=<?php echo ($image); ?>&y=100" border="0" />
    </a>
    </td>
    <?php $ind++; } ?>
    </tr>
    </table>
    <table>
    <tr>
    <td width="830">
      <div id="pic">
      <img id="selimg" height="400" src="scale.php?image=<?php echo ($files[0]);?>&y=400" />
      <br>
      <?php
      
      echo '<font color="ffffff">Filename</font>';
      ?>
      <br>
      </div>
      </td>
     </tr>
    </table>
    the script uses javascript and php to change the image. I'm just not sure how to pull out the variables to echo or print the filename of the displaying image.

  4. #4
    Join Date
    Jan 2007
    Posts
    187
    scale.php?image=<?php echo ($image); ?>&y=100

    that is the images url..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles