HektoR Posted January 9, 2009 Share Posted January 9, 2009 hi all. i trying to get directory items but unsuccessfully . i made this code: <?php $dir = "C:\Program Files\VertrigoServ\www"; if(is_dir($dir)) { $dh = opendir($dir); while($file = readdir($dh) !== false) { echo "filenme :" . $file . "filetype : " . filetype($file); } }else { echo "can not find dir"; echo $dir; } and receive that errors: Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 filenme :1filetype : Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/ Share on other sites More sharing options...
vbnullchar Posted January 9, 2009 Share Posted January 9, 2009 use forward slash str_replace('\\', '/', "C:\Program Files\VertrigoServ\www"); Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-733172 Share on other sites More sharing options...
HektoR Posted January 9, 2009 Author Share Posted January 9, 2009 .... and it will be like $dir = "C:/Program Files/VertrigoServ/www"; if(is_dir($dir)) { $dh = opendir($dir); while($file = readdir($dh) !== false) { filetype($file) . "\n"; } }else { echo "can not find dir"; echo $dir; } i again received error: Warning: filetype() [function.filetype]: Lstat failed for 1 in C:\Program Files\VertrigoServ\www\test\readdir.php on line 10 Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-733176 Share on other sites More sharing options...
GingerRobot Posted January 9, 2009 Share Posted January 9, 2009 This has nothing to do with the direction of the slashes. You have two problems. Your first is operator precedence. The !== operator has higher precedence than the = operator, so it is evaluated first. The result of readdir($dh) !== false is then assigned to $file. So because that is true for each iteration, 1 is assigned to $file. Your second problem is that you need to append the file name to the directory: <?php $dir = "C:\Program Files\VertrigoServ\www"; if(is_dir($dir)) { $dh = opendir($dir); while(($file = readdir($dh)) !== false) { echo "filename :" . $file . "filetype : " . filetype($dir.'\\'.$file); } }else { echo "can not find dir"; echo $dir; } Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-733198 Share on other sites More sharing options...
HektoR Posted January 9, 2009 Author Share Posted January 9, 2009 thank you very much ! Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-733200 Share on other sites More sharing options...
HektoR Posted January 9, 2009 Author Share Posted January 9, 2009 i received something like this : . .. favicon.ico gfx inc index.php readdir.php templates templates_c test Thumbs.db how can i remove "." and ".." ??? Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-733309 Share on other sites More sharing options...
kenrbnsn Posted January 9, 2009 Share Posted January 9, 2009 Why don't you use the glob function? It doesn't return directory entries "." and "..": <?php $dir = "C:/Program Files/VertrigoServ/www"; if (is_dir($dir)) foreach (glob($dir . '/*') as $file) echo "filename :" . $file . "filetype : " . filetype($file) . "<br>\n"; else { echo "can not find dir"; echo $dir; } ?> Much easier to write (IMHO). Ken Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-733324 Share on other sites More sharing options...
HektoR Posted January 13, 2009 Author Share Posted January 13, 2009 great code, thank you .. but what does it means:'/*' ??? Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-736045 Share on other sites More sharing options...
GingerRobot Posted January 13, 2009 Share Posted January 13, 2009 Which part don't you understand? The glob() function? Did you read the manual link that was provided in the post too? Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-736063 Share on other sites More sharing options...
HektoR Posted January 13, 2009 Author Share Posted January 13, 2009 sorry, i just read , and i understand. thank you Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-736078 Share on other sites More sharing options...
HektoR Posted January 19, 2009 Author Share Posted January 19, 2009 does glob has function like mysql (LIKE) . so i have files, for example : 89251545.mp3 15489485.mp3 57875454.mp3 89259999.mp3 is it possible to show only files which starts with 892 with glob function ? Quote Link to comment https://forums.phpfreaks.com/topic/140128-solved-get-directory-items/#findComment-740294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.