Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: newbie needing help

  1. #1
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default newbie needing help

    i am new to the php and forum world and i have copied the following peice of code from the following thread,

    http://www.dynamicdrive.com/forums/a...p/t-12627.html

    $cwd = $_SERVER['REQUEST_URI']."/../../";
    $cwd = substr($cwd, 0, strrpos($cwd, '/' + 1));

    function paintUndersideOfFox($c) {
    echo('<ul class="dirlist">');
    $d = opendir($c);
    while($f = readdir($d)) {
    if(strpos($f, '.') === 0) continue;
    $ff = $c . '/' . $f;
    echo('<li><a href="' . $cwd . $ff . '">' . $ff . '</a></li>');
    if(is_dir($ff)) paintUndersideOfFox($ff);
    }
    echo('</ul>');
    }
    paintUndersideOfFox('..');

    and am trying to get a site map to work and when i run the code it displays all of the folders and files as i wanted, however, I am unable to figure out how to not display certain folders or files.

    could anyone help or point me in the right way?

    Thanks in advance

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    As a security measure, the script will not display any files whose filenames begin with a full stop (.). You could also add an explicit list of files that are not to be displayed:
    Code:
    $hidden = array(
      'hiddenfile1.txt',
      'hiddenfile2.png',
      'hiddenfile3'
    );
    
    function isHidden($fn) {
      return (array_search($hidden, $fn, true) !== false);
    }
    
    $cwd = $_SERVER['REQUEST_URI'] . '/../../';
    $cwd = substr($cwd, 0, strrpos($cwd, '/' + 1));
    
    function paintUndersideOfFox($c) {
      echo('<ul class="dirlist">');
      $d = opendir($c);
      while($f = readdir($d)) {
        if(strpos($f, '.') === 0 || isHidden($f))
          continue;
        $ff = $c . '/' . $f;
        echo('<li><a href="' . $cwd . $ff . '">' . $ff . '</a></li>');
        if(is_dir($ff))
          paintUndersideOfFox($ff);
      }
      echo('</ul>');
    }
    paintUndersideOfFox('..');
    Last edited by Twey; 12-20-2006 at 05:47 PM. Reason: Typo.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you so very much!

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Sorry, typo. Corrected.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Typo? where? if i may ask.

  6. #6
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    sorry, I now see what you were talking about.

  7. #7
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have revised my code accordingly however I am still getting :

    Warning: array_search(): Wrong datatype for second argument in C:\.....\index.php on line 96

    and line 96 is this one:
    return (array_search($hidden, $fn, true) !== false);

    I have tried numerous ways of playing with this, without much luck.

    any thoughts?

    thank you agin for all of your help, very much appreciated.

  8. #8
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i have now tried using print_r to return the values called as well I have read elswere that the second argument is the array that is to be searched and from what i see $fn is to reside within $hidden and if these conditions are true then return as faulse.

    Example of what im trying to say:

    function isHidden($fn) {
    print_r (array_search ($fn[being the value I'm looking for], $hidden[being the array $fn condition should reside in], TRUE) !== FALSE);
    }

    Am I way off base on this?

    or...

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    My error, array_search() seems to take its arguments in the opposite order to every other search function in PHP
    Code:
    return (array_search($fn, $hidden, true) !== false);
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Twey,

    Thanks you for all of your help on this as it has helped me to understand php a little better than before, however when i make the propper adjustments in the code it still does not want to work...it gives me the exact same error. To be quite honest I feel like im so close to the solution and dont want to give up trying to get this peice of code to work however, I also feel like i should maybe hire someone to do this for me as apposed to trying to figure it out myself. Thanks again for all of the efforts you have put into helping me. If there is anything at all you can see that still may be causeing this, please feel free to respond to this posting.

    Once again thanks alot.

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
  •