Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 1st, 2005, 3:59 AM   #1
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
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>&nbsp;</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>&nbsp;</p><p>&nbsp;</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
magic_e is offline   Reply With Quote
Old Feb 1st, 2005, 4:29 AM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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.
tempest is offline   Reply With Quote
Old Feb 1st, 2005, 4:59 AM   #3
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
thanx 4 the fast replay tempest i'll give it a try

Last edited by magic_e; Feb 1st, 2005 at 5:06 AM.
magic_e is offline   Reply With Quote
Old Feb 1st, 2005, 5:13 AM   #4
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
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
magic_e is offline   Reply With Quote
Old Feb 1st, 2005, 5:47 AM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
[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.
tempest is offline   Reply With Quote
Old Feb 1st, 2005, 7:24 AM   #6
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
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
magic_e is offline   Reply With Quote
Old Feb 2nd, 2005, 8:09 PM   #7
codetaino
Programmer
 
codetaino's Avatar
 
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4 codetaino is on a distinguished road
the system used with the server is linux or unix? dont the system function shall be used?
__________________
"God bless u all" :)
codetaino is offline   Reply With Quote
Old Feb 3rd, 2005, 4:11 AM   #8
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
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
magic_e is offline   Reply With Quote
Old Feb 4th, 2005, 10:37 PM   #9
codetaino
Programmer
 
codetaino's Avatar
 
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4 codetaino is on a distinguished road
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.
codetaino is offline   Reply With Quote
Old Feb 6th, 2005, 4:08 PM   #10
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
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.
magic_e is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC