We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39073
    • 15 Posts
    Whistlemaker, I wound up using your php to create an unordered list of all the jpeg files in the directory, and then using a javascript slideshow tutorial I found.

    I have one question - is it possible, using your php, to include the file name of each image without the .jpg extension, in a paragraph tag? What would I have to add to the following to add that where I have "File Name Here"?

    $files = scandir($imagedir);
      
    $html = '<ul class="slides">';
     
    foreach ($files as $filename) {
        if(strstr($filename, '.jpg'))
        {
            $html .= '<li><img src="'.$imagedir.'/'.$filename.'" alt=" " /><p class=flexcaption>"File Name Here"</p></li>';
        }
    } 
      
    $html .= '</ul>';
      
    return $html;


    Unfortunately I have no knowledge of PHP (it's on my list of things to learn, but unfortunately time hasn't permitted at this stage).

    Thank you so much everyone for your help.
    • discuss.answer
      You'll want the "basename()" function: http://php.net/manual/en/function.basename.php
      <p class=flexcaption>'. basename($filename, '.jpg') .'</p>

      [ed. note: sottwell last edited this post 11 years, 5 months ago.]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 39073
        • 15 Posts
        Thank you Susan!!!

        Can't believe it was so easy - I was looking on stack overflow and all the answers involved multiple lines of code, "if"s and "for"s.

        Thanks.
        • For interesting additional information and usage, see the comments to the PHP documentation, especially Swedish Boy's example of using basename() to strip a variable extension using the pathinfo() function to determine the actual extension, then using basename() to get the stripped filename.
          $file = 'image.jpg';
          
          $info = pathinfo($file);
          $file_name =  basename($file,'.'.$info['extension']);
          
          echo $file_name; // outputs 'image'
          
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 32316
            • 387 Posts
            glad my code helped

            the php docs and the comments to them are very helpful both as a reference and a learning tool - I use them before doing any internet search, usually with good results.