Advanced Search

Results 1 to 2 of 2

Thread: I-frame Contents

  1. #1
    Join Date
    Mar 2006
    Location
    Nashville, TN
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default I-frame Contents

    I am not sure why this is not working. When Users click on a file in the list box it should load into the iframe.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>

    <?
    echo ("<h1>Directory Files:</h1>");

    function 
    getFiles($path) {
       
    //Function takes a path, and returns a numerically indexed array of associative arrays containing file information,
       //sorted by the file name (case insensitive).  If two files are identical when compared without case, they will sort
       //relative to each other in the order presented by readdir()
       
    $files = array();
       
    $fileNames = array();
       
    $i 0;
      
       if (
    is_dir($path)) {
           if (
    $dh opendir($path)) {
               while ((
    $file readdir($dh)) !== false) {
                   if (
    $file == "." || $file == "..") continue;
                   
    $fullpath $path "/" $file;
                   
    $fkey strtolower($file);
                   while (
    array_key_exists($fkey,$fileNames)) $fkey .= " ";
                   
    $a stat($fullpath);
                   
    $files[$fkey]['size'] = $a['size'];
                   if (
    $a['size'] == 0$files[$fkey]['sizetext'] = "-";
                   else if (
    $a['size'] > 1024$files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
                   else if (
    $a['size'] > 1024*1024$files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
                   else 
    $files[$fkey]['sizetext'] = $a['size'] . " bytes";
                   
    $files[$fkey]['name'] = $file;
                   
    $files[$fkey]['type'] = filetype($fullpath);
                   
    $fileNames[$i++] = $fkey;
               }
               
    closedir($dh);
           } else die (
    "Cannot open directory:  $path");
       } else die (
    "Path is not a directory:  $path");
       
    sort($fileNames,SORT_STRING);
       
    $sortedFiles = array();
       
    $i 0;
       foreach(
    $fileNames as $f$sortedFiles[$i++] = $files[$f];
      
       return 
    $sortedFiles;
    }

    $files getFiles("./");
    foreach (
    $files as $file) print "&nbsp;&nbsp;&nbsp;&nbsp;<b><a href=\"$file[name]\">$file[name]</a></b><br>\n";
    ?>
    <form id="form1" name="form1" method="get" action="">
    <select name="file" size="10">
      <? foreach ($files as $file)  echo "<option value=\"$file[name]\">$file[name]</option><br>\n"?>
    </select>
    <br />
        <input type="submit" name="Submit" value="Open File" />
    </form>
    <br /><br />
    <iframe name="file" src="<? $_REQUEST["file"]; ?>" width="200" height="250" frameborder="1"></iframe>
    </body>
    </html>
    Edit:
    NeverMind I figured it out I forgot the echo in the src of the iframe. So it should read:
    PHP Code:
    <? echo $_REQUEST["file"]; ?>
    Last edited by benslayton; 03-02-2007 at 11:27 PM. Reason: answer found out

  2. #2
    Join Date
    Mar 2006
    Location
    Nashville, TN
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    I would like to know how to allow only .txt file in the list box.

Bookmarks

Posting Permissions

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