scandir

This is a discussion on scandir within the PHP Language forums, part of the PHP Programming Forums category; Hi! I've got a tiny little problem :-) with the following code: .... function get_styles($dir) { $tmp = scandir($dir); // Line 19 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2006
René Kälin
 
Posts: n/a
Default scandir

Hi!

I've got a tiny little problem :-) with the following code:

....

function get_styles($dir) {
$tmp = scandir($dir); // Line 19
echo $dir; echo $tmp;
foreach ($tmp as $key => $datei) {
if (substr($datei, -3) == "css") {
$tmpdatei = substr($datei, 0, (strlen($datei) - 4));
$trimmed_array[$key] = $tmpdatei; }
}
return $trimmed_array;
}

function init_styleswitcher() {
if (!isset($_SESSION['styles'])) { $_SESSION['styles'] =
get_styles($cssdir); }

....

I get these Errormessages, the 2nd and the 3rd are consequences of the
first I suppose:

Warning: scandir() [function.scandir.html]: (errno 22): Unknown error: 0
in /home/designw/public_html/styleswitcher/phplib/styleswitcher.php on
line 19

Warning: Invalid argument supplied for foreach() in
/home/designw/public_html/styleswitcher/phplib/styleswitcher.php on line 21

Warning: in_array() [function.in-array.html]: Wrong datatype for second
argument in
/home/designw/public_html/styleswitcher/phplib/styleswitcher.php on line 34

This function doesn't work anymore since I try to use it in sessions and
I don't understand it. Can anyone give me a hint?

Thanks
rené
Reply With Quote
  #2 (permalink)  
Old 02-27-2006
samudasu
 
Posts: n/a
Default Re: scandir

What's the value of $dir?

Reply With Quote
  #3 (permalink)  
Old 02-27-2006
samudasu
 
Posts: n/a
Default Re: scandir

Looking closer at your code i think i spotted the problem. $cssdir
needs to have global scope or else init_styleswitcher() needs an
argument passed to it. In this case init_styleswitcher($cssdir).
If you don't want to add an argument to init_styleswitcher() then you
change get_styles($cssdir); to get_styles($GLOBALS['cssdir']);

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:25 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0