Search
Left Quote    Knowledge speaks, but wisdom listens.
- Jimi Hendrix    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Required ASAP.
  This user is offline  abhi
  Subject: "Required ASAP." Posted: @ 2:58 pm on Nov 27 2007   
Member #: 379
Rank: User - (19)
Since: 07/30/07
Posts: 19
From: Michigan

So guys this is what I want....a PHP code for doing the following:
1. Read the current directory.
2. Save .txt file names into an array.
3. Processs each file with the correct logic.

It would be really great if anybody can provide me the PHP code or guide me somewhere as to where to look for steps 1 and 2.Its very urgent.


abhishekitty@ya
hoo.com |     Viewed: 17,803 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: Required ASAP." Posted: @ 3:47 pm on Nov 27 2007    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

have a look at the opendir function. there are examples of how to read the contents of a directory.




please note that the above post is likely made up in its entirety.

    Viewed: 17,796 Times | Reply to This | To top
  This user is offline  abhi
  Subject: "re: Required ASAP." Posted: @ 4:05 pm on Nov 27 2007    
Member #: 379
Rank: User - (19)
Since: 07/30/07
Posts: 19
From: Michigan



Edited at 04:46:37 pm on 11/27/07


abhishekitty@ya
hoo.com |     Viewed: 17,792 Times | Reply to This | To top
  This user is offline  abhi
  Subject: "re: Required ASAP." Posted: @ 4:45 pm on Nov 27 2007    
Member #: 379
Rank: User - (19)
Since: 07/30/07
Posts: 19
From: Michigan

  misterhaan said...

< i> have a look at the opendir function. there are examples of how to read the contents of a directory.

Yeah...thats right misterhaan....I checked the opendir function...that was helpful but now I am not able to figure out a way of saving the .txt files into an array after I read them from the directory.....P lease advise...!!!




abhishekitty@ya
hoo.com |     Viewed: 17,785 Times | Reply to This | To top
  This user is offline  abhi
  Subject: "re: Required ASAP." Posted: @ 9:04 pm on Nov 27 2007    
Member #: 379
Rank: User - (19)
Since: 07/30/07
Posts: 19
From: Michigan

Please have a look at this code and tell me if its right...!!!

This is just to put the filenames into an Array,sort the array and then what you want to do with the filename...got it from one of the websites...!!!P lease check...!!!


All you have to do is read the filenames into an array, sort the array and then do what you want with the filenames.... like this....

<?php
$i = 0;
$arraycount = 0;
$home="/h ome/cabal/publi c_html/b146/adm in/$stats" ;;

if ($stats)
{
$dircheck=&quo t;/home/cabal/p ublic_html/b146 /admin/$stats& quot;;
if (is_dir($dirche ck))
{
if ($handle = opendir($home))
{
while (false !== ($file = readdir($handle )))
{
if ($file != "." && $file != ".."
{
$path = "$home/$f ile";
$extension = array_pop(explo de('.', basename($path) ));
$filearray[$i] = $file;
$i++;
}
}
}
closedir($handl e);

}
else
{
echo "INCORREC T SELECTION" ;;
}

}

else

{
echo "NOTHING SELECTED" ;
}
echo "&nbs p;";

echo("< ;table width='100%' border='1'> ;<tr>< td><b> <font color='#ff0000 '>";
echo("$st ats : Log File";
echo("< ;/b></fon t></td> ;<td>< font color='#FF0000 '><b> Page Views</b> </font>&l t;/td></t r>";
sort($filearray );
reset($filearra y);
while (list($key, $val) = each($filearray ))
{
$includearray = "$home/$f ilearray[$key] ";
echo("< ;tr><td&g t;";
echo("$va l";
echo("< ;/td><td& gt;";
include($includ earray);
echo("< ;/td></tr >";

}
echo("< ;/table>&qu ot;

?>




abhishekitty@ya
hoo.com |     Viewed: 17,768 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: Required ASAP." Posted: @ 4:09 pm on Nov 28 2007    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

it looks mostly like it should work. the part i




please note that the above post is likely made up in its entirety.

    Viewed: 17,751 Times | Reply to This | To top
  This user is offline  abhi
  Subject: "re: Required ASAP." Posted: @ 9:35 am on Dec 01 2007    
Member #: 379
Rank: User - (19)
Since: 07/30/07
Posts: 19
From: Michigan

Can someone please suggest why the following code is not working...I improvedthe code that I posted earlier.....It goes as follows...


<?php
$i = 0;
$arraycount = 0;
$home="/w ebapps/tomcat-d ocs";

if ($stats)
{
$dircheck=&quo t;/webapps/tomc at-docs";
if (is_dir($dirche ck))
{
if ($handle = opendir($home))
{
while (false !== ($file = readdir($handle )))
{
if ($file != "." && $file != ".." ;
{
$path = "$home/$f ile";
$extension = array_pop(explo de('.', basename($path) ));
$filearray[$i] = $file;
$i++;
}
}
}
closedir($handl e);

}
else
{
echo "INCORREC T SELECTION" ;;
}

}

else

{
echo "NOTHING SELECTED" ;
}
echo "&nbs p;";

echo("< ;table width='100%' border='1'> ;<tr>< td><b> <font color='#ff0000 '>";< br /> echo("$st ats : Log File";
echo("< ;/b></fon t></td> ;<td>< font color='#FF0000 '><b> Page Views</b> </font>&l t;/td></t r>"; sort($filearray );
reset($filearra y);
while (list($key, $val) = each($filearray ))
{
$includearray = "$home/$f ilearray[$key] ";
echo("< ;tr><td&g t;";
echo("$va l";
echo("< ;/td><td& gt;";
include($includ earray);
echo("< ;/td></tr >";

}
echo("< ;/table>&qu ot;;

?>
The line where it is referring to the main directory is not working fine and also and also where it has to create a table of files(the last part of the code)is not working fine either.
Please help...!!!




abhishekitty@ya
hoo.com |     Viewed: 17,673 Times | Reply to This | To top
  This user is offline  abhi
  Subject: "re: Required ASAP." Posted: @ 9:41 am on Dec 01 2007    
Member #: 379
Rank: User - (19)
Since: 07/30/07
Posts: 19
From: Michigan

  misterhaan said...

< i> it looks mostly like it should work. the part i




abhishekitty@ya
hoo.com |     Viewed: 17,671 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: Required ASAP." Posted: @ 3:58 pm on Dec 03 2007    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

what




please note that the above post is likely made up in its entirety.

    Viewed: 17,612 Times | Reply to This | To top
  This user is offline  abhi
  Subject: "re: Required ASAP." Posted: @ 1:31 pm on Dec 04 2007    
Member #: 379
Rank: User - (19)
Since: 07/30/07
Posts: 19
From: Michigan

  misterhaan said...

< i> what




abhishekitty@ya
hoo.com |     Viewed: 17,586 Times | Reply to This | To top
  This user is offline  abhi
  Subject: "re: Required ASAP." Posted: @ 8:27 pm on Dec 04 2007    
Member #: 379
Rank: User - (19)
Since: 07/30/07
Posts: 19
From: Michigan

The real problem is the parse error on this line...It says...!!!
$path = "$home/$f ile";
Please advice...!!!




abhishekitty@ya
hoo.com |     Viewed: 17,567 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Required ASAP." Posted: @ 9:50 pm on Dec 04 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Should the $path variable be: $path = "/" .$home."/ ".$file. "";

No, that path will not work on our machines. Localhost is your computer/webser ver. I've never used TomCat - so I really can't help you out there. Im kind of at a loss here.

In your other post, you said it gives you an error, then you pasted code. That tells me that you must have closed PHP right where its showing PHP code- so look for a ?> around that point.




-bs0d | AllSyntax.com

    Viewed: 17,559 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: Required ASAP." Posted: @ 3:58 pm on Dec 05 2007    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

< i>if ($file != "." && $file != ".." ;
you




please note that the above post is likely made up in its entirety.

    Viewed: 17,531 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank