Open sub directories and only files with "xyz.html"

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arvi608
Forum Newbie
Posts: 1
Joined: Fri Jul 18, 2014 6:14 pm

Open sub directories and only files with "xyz.html"

Post by arvi608 »

Hi all,

I want to accomplish :to open a sub directory from "/home/www/htdocs/icm/sessions" -> there are sub folders in sessions and in those folders there are "chromatin.html" files which i want them to populate in a dropdown box.

I am not able to open the files as i intended to, Please let me know where I am doing it wrong

Code: Select all

<?php

echo "<select name='files' , fixedscript, ID='file_selector'>";


$files = scandir("/home/www/abc/def/seq");

foreach ($files as $file){
$ext = substr($file, -4);

if(strtolower($ext) == 'xyz.html')
{

$file = substr($file, 0, strrpos($file, '.'));

echo '<option value="' . $file . 'xyz.html">' . $file . '</option>';
}
}
echo "</select>";



?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Open sub directories and only files with "xyz.html"

Post by Celauran »

arvi608 wrote:

Code: Select all

$ext = substr($file, -4);

if(strtolower($ext) == 'xyz.html') {
That's not ever going to be true. You're taking the last four characters of the filename and then checking if those four characters equal an eight character string.
Post Reply