basically i have created a selection box which display the files i have got in a certain folder which are xml files, my problem is that i am unsure how to save the content of the file selected as a live variable which changes on different selected which the variable can be called to show a table.

here my code so far;


$dir = opendir("C:/xampp/htdocs/xml");

//List files in images directory
while (($file = readdir($dir)) !== false)
      $last4 = substr($file, -4); 
      if ($last4 == ".xml")
         $files[] = $file;


printf ('<select>');

foreach($files as $let => $val){
    printf ('<option value="'.$let.'">'.$val.'</option>');

printf ('</select>');

4 Years
Discussion Span
Last Post by veedeoo


Just need patience in waiting for the response. All expert and master coders are volunteers, and ONE junior volunteer like myself is always lazy all the time :)..

In fact, I think I already posted many variations of read_dir function in this forum.. Since, I don't keep a record of those little things, let me write another one.. always new every time..

here we go... I don't have the chance to test my codes below, but I am pretty sure it will work..


        function xmlFiles($dir,$ext) {
        $d = dir($dir); 
        while (false!== ($file = $d->read())) 
        $extension = substr($file, strrpos($file, '.')); 
        if(($extension == '.'. $ext))
        $xml[$file] = $file; 

        return $xml; 

to use the function above, do it like this

        $theseXml = xmlFiles('./xml/','xml');
        echo '<select>';
        foreach($theseXml as $file){
        echo '<option value="'.$file.'">'. $file .'</option>';


        echo '</select>';

Always refer to directories in reference with the htdocs directory. Everything within this directory are viewable through a browser. So, this C:/xampp/htdocs/xml is not valid if you are using a PHP script located inside the htdocs directory.

If you want to use something similar to that, then you will have to define it like this.

    define('ROOT', dirname(__FILE__));

and your xml directory will can be referenced like this.. assuming that it is located in the htdocs or root directory.

    $xmlDir = ROOT.DS .'xml'. DS;

Edited by veedeoo: info added

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.