View Full Version : 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/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:
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('..');
Thank you so very much!:D
Typo? where? if i may ask.
sorry, I now see what you were talking about.
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.
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...
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);
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.:( :)
That's peculiar. You see the same error, on the same line?
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.