![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
not listing all files?
hi,
i'm having major problems with a script i wrote The script is ment to list the whole directory's files and automatically generate either an image or text line depending on the value set in the database [PHP]<body> <style> <!-- BODY{ scrollbar-face-color:''; scrollbar-arrow-color:''; scrollbar-track-color:''; scrollbar-shadow-color:''; scrollbar-highlight-color:''; scrollbar-3dlight-color:''; scrollbar-darkshadow-Color:''; background-color: transparent; } --> </style> </body> <?php include_once('../manik/config.php'); $sqdb = mysql_connect($dbhost,$dbusname,$dbpass) or die("Unable to connect to mysql server"); mysql_select_db($dbused,$sqdb) or die("Unable to Find supplied database"); $res = mysql_query("SELECT * FROM settings",$sqdb); while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { $mg = $row['mmg']; $tmg = $row['imgtx']; $mlf = $row['nmsg']; $ftm = $row['ftmsg']; } $fred = getcwd()."/"; $fredon = dirname($fred); $dir4me = @opendir($fred) or header("Status: 404 Not Found"); if ($tmg == 1) { while (false !== ($file = readdir($dir4me))) { if ($file != "." && $file != ".." && $file !=".htaccess" && $file != ".htpasswrd" && $file != "index.php"&& $file != "index.html"&& $file != "manik.php" && $file != "~.htaccess" && $file != "~.passwrd" && $file != ".passwd"&& $file != "~passwd"&& $file != "~.passwd"&& $file != ".log") { /* Remeber To provent a certain file or filetype add it to this line*/ echo "<table border=0 width=100% id=Drlist><tr><td><p align=center>$file</td><td><a title=Listen href=".rawurlencode($file)."><p align=center><img border=0 src=$mg></a></p></td></tr></table>"; } } closedir($dir4me); }else { while (false !== ($file = readdir($dir4me))) { if ($file != "." && $file != ".." && $file !=".htaccess" && $file != ".htpasswrd" && $file != "index.php"&& $file != "index.html"&& $file != "manik.php" && $file != "~.htaccess" && $file != "~.passwrd" && $file != ".passwd"&& $file != "~passwd"&& $file != "~.passwd"&& $file != ".log") { /* Remeber To provent a certain file or filetype add it to this line*/ echo "<table border=0 width=100% id=Drlist><tr><td><p align=center>$file</td><td><a title= href=".rawurlencode($file)."><p align=center>$mlf</a></p></td></tr></table>"; } } closedir($dir4me); } mysql_close($sqdb); ?> <script language=JavaScript> <!-- var message="Sorry but Right Click has been disabled!"; /////////////////////////////////// function clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if (document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){ alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmousedown=clickIE4; } document.oncontextmenu=new Function("alert(message);return false") // --> </script> <?php //This is the footer It should NOT be edited!!!! //To Change the Footer Message Edit it via the Admin Control Panel!!! echo "<p> </p><p align=center>$ftm</p>"; echo "<style type=text/css><!--.style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;}--></style><div align=center><p> </p><p> </p><table cellpadding=4 cellspacing=1 border=0 bgcolor=#005177 align=center><tr><td bgcolor=#D9E2E7><div align=center class=style1>Powered by <a href=http://www.underground-vinyls.co.uk/Projects/Manik/ target=_blank>Manik Script</a> v1.5 By Stuart Bell </div></td></tr></table></div>"; ?>[/PHP] my problem is my script wont list every single file in the directory The Directory has over 600 files and only around 150 - 200 max are shown any help wud be greatful thanx |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Here's an alternative solution...
[php]function getFiles() { $str = `ls`; $str = str_replace("\n", "\t", $str); $str = explode("\t", $str); $ret = array(); $count = 0; for($i=0;$i<count($str);$i++) if(is_file($str[$i])) $ret[$count++] = $str[$i]; return $ret; }[/php]
__________________
Last edited by tempest; Feb 1st, 2005 at 4:32 AM. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
thanx 4 the fast replay tempest i'll give it a try
Last edited by magic_e; Feb 1st, 2005 at 5:06 AM. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
after trying your code tempest i found it to be far too slow unless it's the way i use your function (which is likely)
[PHP]<?php getFiles(); function getFiles() { $str = `ls`; $str = str_replace("\n", "\t", $str); $str = explode("\t", $str); $ret = array(); $count = 0; for($i=0;$i<count($str);$i++) if(is_file($str[$i])) $ret[$count++] = $str[$i]; return $ret; } while (false !== ($file == $ret)) { if ($file != "." && $file != ".." && $file !=".htaccess" && $file != ".htpasswrd" && $file != "index.php"&& $file != "index.html"&& $file != "manik.php" && $file != "~.htaccess" && $file != "~.passwrd" && $file != ".passwd"&& $file != "~passwd"&& $file != "~.passwd"&& $file != ".log") { /* Remeber To provent a certain file or filetype add it to this line*/ echo "<table border=0 width=100% id=Drlist><tr><td><p align=center>$file</td><td><a title=Listen href=".rawurlencode($file)."><p align=center><img border=0 src=$mg></a></p></td></tr></table>"; } } ?>[/PHP] which is what i would expect since i dont have a clue at what the hell i'm doing any help wud be greatly apreciated thanx magic e |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
[php]<?php
function getFiles() { $str = `ls`; $str = str_replace("\n", "\t", $str); $str = explode("\t", $str); $ret = array(); $count = 0; for($i=0;$i<count($str);$i++) if(is_file($str[$i])) $ret[$count++] = $str[$i]; return $ret; } $files = getFiles(); for($i=0;$i<count($files);$i++) if(substr($files[$i], 0, 1) != "." && substr($files[$i], 0, 1) != "~" && substr($files[$i], 0, 5) != "index" && $files[$i] != "manik.php") echo "<table border=0 width=100% id=Drlist><tr><td><p align=center>$file</td><td><a title=Listen href=".rawurlencode($files[$i])."><p align=center><img border=0 src=$mg></a></p></td></tr></table>";} ?>[/php]
__________________
Last edited by tempest; Feb 1st, 2005 at 5:51 AM. |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
thanx again tempest for the super fast responce,
Thanx 4 the code but now it doesn't list the files it simply displays a blank page not sure why?? thanx again magic e |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4
![]() |
the system used with the server is linux or unix? dont the system function shall be used?
__________________
"God bless u all" :) |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
thanx alot to everyone who has replyed
@codetaino thanx 4 the info The problem did lye with the OS as codetaino sed, after testing the script on a linux server i found that it worked. But there's my problem the script needs to be universal so it will work on almost any server wether it be windoz or linux, can any1 plz tell me how this can be done? thanx again magic e |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4
![]() |
I found this code.... and worked for me on windows with 1011 files... try it on linux.... i think is kidna the same as your first post... but simple
[PHP]<?php $files = array(); $dir = opendir('.'); while(($file = readdir($dir)) !== false) { if($file !== '.' && $file !== '..' && !is_dir($file)) { $files[] = $file; } } closedir($dir); sort($files); for($i=0; $i<count($files); $i++) { echo $files[$i].'<br>'; } ?>[/PHP] hope it helps -codetaino
__________________
"God bless u all" :) Last edited by codetaino; Feb 4th, 2005 at 11:05 PM. |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
thanx alot codetaino you code worked a treat and at alarming speed i might add
but after i had customized it so that it was the same as before it fails to list all the files i now think the problem lies with the way the files are listed but thats another story thanks again magic e Last edited by magic_e; Feb 6th, 2005 at 4:18 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|