PDA

View Full Version : newbie needing help



Telp
12-19-2006, 07:52 PM
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/archive/index.php/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:):confused:

Twey
12-20-2006, 08:45 AM
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:
$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('..');

Telp
12-20-2006, 04:14 PM
Thank you so very much!:D

Twey
12-20-2006, 05:48 PM
Sorry, typo. Corrected.

Telp
12-20-2006, 07:22 PM
Typo? where? if i may ask.

Telp
12-20-2006, 07:23 PM
sorry, I now see what you were talking about.

Telp
12-20-2006, 07:30 PM
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.

Telp
12-27-2006, 09:04 PM
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...

Twey
12-27-2006, 11:44 PM
My error, array_search() seems to take its arguments in the opposite order to every other search function in PHP :)
return (array_search($fn, $hidden, true) !== false);

Telp
12-28-2006, 04:53 PM
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.:( :)

Twey
12-28-2006, 09:46 PM
That's peculiar. You see the same error, on the same line?