here is what i made up.....

chronicle_lister.php

<?php 
$val_array_=_array(); 
$handle_=_opendir('/var/www/coleclan/include/chronicle_data'); 
while_(false_!==_($files_=_readdir($handle)))_{ 
array_push($val_array,$files); 
} 
closedir(); 

sort($val_array); 


foreach($val_array_as_$item){ 
include_$item; 
} 
?> 

i get the following error when accessing the page....

Fatal error: input in flex scanner failed in /var/www/coleclan/include/chronicle_data on line 1

strange......

what is realy odd is that i had all this in a different directory for testing purposes first.

instead of including the files, i was simpily just echoing to the screen. it worked.

so then i changed the echo code to include code, and moved the file to it's permanant home, changed the path for the opendir() .. upon accessing it, it was broken.

(((2nd EDIT)))

Okay... so for grins... i changed the code back to a listing (echo each filename) and all is good... it is when i use the INCLUDE instead that it is broken.

what is wrong?!

all i want to do is grab the files in a specified folder and include them all in sequence as sorted by filename (as they are named like "12Feb052210", "15Feb051734", etc) ...

this is for the puropse of accomplishing something that resembles a blog... i add a file to the folder, it is included. simple.

help!

    You have underscores on everything.

    <?php  
    $val_array = array();
    $handle = opendir('/var/www/coleclan/include/chronicle_data');
    while (false_!== ($files = readdir($handle))) {
    array_push($val_array,$files);
    }
    closedir($handle); sort($val_array); foreach($val_array as $item){
    include($item);
    }
    ?>

      I had to paste this from another post as it went stale and i need the answer.

      ignore all in-appropriate underscores as they are only the result of the copy-paste.

      any ideas why it works until i use INCLUDE in the FOREACH statement?

        Looks like you need to expand on your path if you are going to use include() statement.

        include("include/chronicle_data/$item");
          
          Warning: Failed opening 'include/chronicle_data/.' for inclusion (include_path='.:/usr/share/pear') in /var/www/coleclan/include/chronicle_lister.php on line 13
          
          Warning: Failed opening 'include/chronicle_data/..' for inclusion (include_path='.:/usr/share/pear') in /var/www/coleclan/include/chronicle_lister.php on line 13
          
          Warning: Failed opening 'include/chronicle_data/24Feb05143449.php' for inclusion (include_path='.:/usr/share/pear') in /var/www/coleclan/include/chronicle_lister.php on line 13
          

          This is the result after the "Expansion" of the include line.

          I did notice it tried to include . and .. which obviously do not need inclusion, filtering i will deal with after i get the basic function to work right.

          Still stumped.

            just does not work...

            I copied your code in it's entirety.

            changed only 2 little bits...

            here is the final version of your code as modified by me. The changes are the PATH and the ECHO statement in the FOREACH at the bottom....

            <?php
            // set array variable for listing files later in script
            $file_array = Array();
            
            // establish path to directory
            // insure to include the forward slash on end
            $dirpath = "/var/www/coleclan/include/chronicle_data/";
            
            // open directory for evaluation
            $handle = opendir($dirpath);
            
            // loop through directory till last file
            while (false !== ($file = readdir($handle))) {
            
            // filter out any non-files and non-directories
            if ($file != "." && $file != "..") {
            
                // add file name to directory path
                $path = $dirpath.$file;
            
                if (is_file($path)) {
                    // get file name + extension
                    $file = basename($path);
            
                    // add file to array varaible
                    array_push($file_array,$file);
                }
            }
            }
            
            // close directory
            closedir($handle);
            
            // set array in alphabetic order
            // Note: upper cased letters will come before lower cased letters
            sort($file_array);
            
            // loop through the array and assign to varaible
            foreach ($file_array as $value) {
            
            // print out variable
            include $value;
            
            }
            
            ?>
            

            the error I get is as follows:

            
            Warning: Failed opening '24Feb05143449.php' for inclusion (include_path='.:/usr/share/pear') in /var/www/coleclan/include/chronicle_lister.php on line 42
            

            Question:

            Perhaps I need to have this code included and then pull the includes for $value in the parent file? e.g.: index.php has include chronicle_lister.php in it. after the include 'chronicle_lister.php'; line, i should mabey add the foreach loop????

            Help! I desparately want this to work!

              You did not supply a path to your file

              Now:

              include $value;

              Should be:

              include("include/chronicle_data/$value");

                okay! I had no idea i needed to put that path back in... lol ... it's always the simple stuff...

                last thing... i looked around for info on sort() .... i cant figure out how to reverse the order... i need newest files first. I made my system use a time stamp to number the files.... so it can be sorted just as it is now, i just need the sort reversed so the newest file in the directory is listed first, and the oldest last.

                how?

                Beavis2084

                  http://us3.php.net/manual/en/function.sort.php

                  sort($file_array, SORT_NUMERIC);

                  Also try:

                  sort($file_array, SORT_DESC);

                  But remember, 24dec05143449 will come before 24Feb05143449 because of the "d" in dec.

                  I would use time() for creating your files or naming, then you can order them by numeric and every file will be different.

                  You then can know when the date of the file is by just doing the folllowing.

                  $filename = str_replace("\.php","",$filename);
                  echo date("m-d-y h:i",$filename);

                    Thanks again Fred.

                    I ended up locating rsort() ... it is "reverse"-sort ... lol.

                    got it all working great!

                    Beavis2084

                      Write a Reply...