Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Getting Results


  • Please log in to reply
3 replies to this topic

#1 Lop

Lop

    Speaks fluent binary

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1112 posts

Posted 05 January 2007 - 02:35 PM

I want to display a bunch of results on a webpage as they occur from a PHP script. Basically, I want to execute a PHP script and display the results of a file list.

So, if I am displaying a list of files in a directory I'd like to show the path and filename as they are displayed.

I'd also like PHP to be the language that I display the results with because I know it best. Any ideas?
  • 0

#2 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 06 January 2007 - 10:29 PM

Im kind of confused with what you want, but from what I gather you could use file() for the first part of your question, which turns the entire contents of a file into an array, each new line is a new array element.

As for the second part, are you looking for a recursive directory script? Im sure its not exactly what you are looking for but it should move you into the right direction.

<?php

function DirectoryTree($dir)
{
$tree = array();
$dirs = array(array($dir, &$tree));

for($i = 0; $i < count($dirs); ++$i)
{
$d = opendir($dirs[$i][0]);
$tier =& $dirs[$i][1];

while($file = readdir($d)){
if ($file != '.' and $file != '..'){
$path = $dirs[$i][0] . DIRECTORY_SEPARATOR . $file;
if (is_dir($path)){
$tier[$file] = array();
$dirs[] = array($path, &$tier[$file]);
}
else{
$tier[$file] = filesize($path);
}
}
}
}

return $tree;
}

$d = DirectoryTree(getcwd());
var_export($d);

?>


Which will display all the folders recursively down to the file in a multi dimensional array. Its just what I had laying around, I'm sure some basic mods you will have what you want (i think, but im tired and could be way off). It will display something like:

array ( '911 - The First 167 Minutes.avi' => 1419862016, 'All Quiet on the Western Front (1930).avi' => 1356969472, 'ATL (2006)' => array ( 'ATL (2006).avi' => 731054080, 'atlr.lrc.xvid.nfo' => 406, ), 'Borat.avi' => 730834944, 'Donnie Brasco.avi' => 733945856, 'Fahrenheit 911' => array ( 'Fahrenheit 911.avi' => 730007020, ), 'Grapes of Wrath, The (1940).avi' => 734814208, 'Miami Vice.avi' => 735946752, 'Pirates Of The Caribbean' => array ( 'Pirates Of The Caribbean.avi' => 2048030208, ), 'The Da Vinci Code' => array ( 'fte-tdce.cd1.dvdrip.xvid.avi' => 0, 'fte-tdce.cd2.dvdrip.xvid.avi' => 733380608, 'fte-tdce.dvdrip.xvid.nfo' => 538, ), 'The Godfather (1972) - CD1.avi' => 725178368, 'The Godfather (1972) - CD2.avi' => 734908416, 'The Sentinel' => array ( 'CD1' => array ( 'the.sentinel.haf.cd1.bin' => 842573424, 'the.sentinel.haf.cd1.cue' => 132, ), 'CD2' => array ( 'the.sentinel.haf.cd2.bin' => 841611456, 'the.sentinel.haf.cd2.cue' => 132, ), ), 'The.Marksman.2005.DVDRip.avi' => 734236672, 'Thumbs.db' => 5632, 'VLC media player.lnk' => 739, 'You, Me and Dupree.avi' => 734013440, )


  • 0

#3 Lop

Lop

    Speaks fluent binary

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1112 posts

Posted 10 January 2007 - 06:15 AM

Right, I get how to do the PHP part, what I want to do is display that data as I get it on the webpage without refreshing. Sort of like the "Thread Spy" here on CodeCall (in the quick links menu). Any ideas?
  • 0

#4 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 10 January 2007 - 10:16 AM

Well from what I understand, getting data from the server without refreshing the page is the perfect application of AJAX. I'm not sure you can do that in php alone.
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download