SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    I searched for a good file manager ( used for an intranet ) now for 3 days, but haven't really found anything applicable. there are a few, but I couldn't get them to work properly.

    I now used a code from the php4 wrox book. It's almost working fine, the directories and files are listed and are also turned into links, but once I click a directory link for example, it doesn't do anything. It reloads ( $PHP_SELF ) but for some reason it doesn't take the new value for the new dir variable. The generated link looks like this :

    http://localhost/wrox/php_dir/navigator.php?dir=./test1

    But instead of switching to the tes1 dir, it stays in the current dir, which is "."

    PHP Code:

    <?php
    #navigator.php
    #include "common.inc";

    $default_dir ".";
    $text_file_array = array( "txt""htm""html""php""inc""dat" );
    $image_file_array = array("gif""jpeg""jpg""png");

    function 
    html_header() {
       
    ?>
       <HTML>
       <HEAD><TITLE>Welcome to Web Text Editor</TITLE></HEAD>
       <BODY>
       <?php
    }

    function 
    html_footer() {
       
    ?>
       </BODY>
       </HTML>
       <?php
    }

    function 
    error_message($msg) {
       
    html_header();
       echo 
    "<SCRIPT>alert(\"$msg\"); history.go(-1)</SCRIPT>";
       
    html_footer();
       exit;
    }

    function 
    display() {
       global 
    $filename$dir$text_file_array$image_file_array;

       
    $extension array_pop(explode("."$filename));
       if(
    in_array($extension$text_file_array)) {
          
    readfile("$dir/$filename");
       }
       else if(
    in_array($extension$image_file_array)) {
                   echo 
    "<IMG SRC=\"$dir/$filename\">";
       }
       else echo 
    "Cannot be displayed. $dir/$filename has not been
                   recognised as a text file, nor as a valid image file. "
    ;
    }

    function 
    dir_page() {
       global 
    $dir$default_dir$PHP_SELF$default_filename;

       if(
    $dir == '') {
          
    $dir $default_dir;
       }
       
    $dp opendir($dir);

    ?>
    <TABLE BORDER="0" WIDTH="100%" CELLSPACING="0" CELLPADDING="0">
    <?php
       
    while($file readdir($dp)) $filenames[] = $file;

       
    sort($filenames);

       for(
    $i 0$i count($filenames); $i++)
       {
          
    $file $filenames[$i];
       if(
    $dir == $default_dir && ($file == "." || $file == ".."))
             continue;
          if(
    is_dir("$dir/$file") && $file == ".")
             continue;
          if(
    is_dir("$dir/$file")) {
             if(
    $file == ".."){
                
    $current_dir basename($dir);
                
    $parent_dir ereg_replace("/$current_dir$","",$dir);
                echo 
    "<TR><TD WIDTH=\"100%\" NOWRAP>
                   <A HREF=\"
    $PHP_SELF?dir=$parent_dir\">$file/
                   </A></TD></TR>\n"
    ;
             }
             else echo 
    "<TR><TD WIDTH=\"100%\" NOWRAP>
                        <A HREF=\"
    $PHP_SELF?dir=$dir/$file\">
                           
    $file/</A></TD></TR>\n";
          }
          else echo 
    "<TR><TD WIDTH=\"100%\" NOWRAP>
                <A HREF=\"
    $PHP_SELF?action=display&dir=$dir&filename=$file\"
                   TARGET=\"_blank\">
    $file</A></TD></TR>\n";
       }
     echo 
    "<h1>" $dir "</h1>";
     
    closedir($dp);
    ?>
    </TABLE>

    <?php

    }

    if(empty(
    $dir) || !ereg($default_dir$dir)) {
       
    $dir $default_dir;
    }

    switch (
    $action) {
       case 
    "display":
          
    display();
          break;
       default:
          
    html_header();
          
    dir_page();
          
    html_footer();
          break;
    }
    ?>


    What am I doing wrong ? I tried webexplorer2, worked fine, but had the same problem as above. Couldn't browse subdirectories. Are there any settings in php.ini that I'm missing ? Maybe something about $PHP_SELF ?


    Any help appreciated ---------- cheers .


    ad

  2. #2
    SitePoint Member
    Join Date
    Jan 2001
    Location
    UK
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SORTED !!!

    Someone on the devshed forum helped me out.

    Was something very easy :

    I just had to turn on : register_globals in the php.ini


    Although the manual says :


    You may want to turn this off if you don't want to clutter your scripts' global scope with user data.

    Haven't got a clue what that means though. Seems like they're advising you to turn it off.

    Probably need to do further reading.


    cheers


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
  •