Jump to content

Help scanning sub dir and open files (newbie)


nvfd412

Recommended Posts

I'm attempting to create a web form that will search a share with multiple sub dir's and open the filename that was submitted in the form, is that possible with out having to hard code all the sub dir's as an array?

Sample of code that will open a file in a single share (\\server\sharedir), but I'm unable to parse the sub dir's to find the same file.  Any idea and help is appreciated.

Code:

<?php
//***** \\\shareDrive\\shareDir
$path ='\\\sharedrive\\sharedir\\';
#################################
// initialize counter
$count = 0;

// set directory name
//$dir = "$path"

//open directory and parse file list
if ($handle = opendir($path)) {
  while (false !== ($file = readdir($handle))) {
// iterate over file list
// print filenames
while (($filename = readdir($handle)) !== false)
{
if (($filename != ".") && ($filename != ".."))
{
$count ++;
//echo $path . "/" . $filename . "\n";
}
}

}
}

//echo "-- $count FILES FOUND --";

###################################

// set file to read
$filename = 'filename';
//echo "($path$filename)";
// open file
$fh = fopen ("$path$filename", "r") or die("Could not open file");
//echo $fh;
// read file
while (!feof($fh))
{
$data = fgets($fh);
echo $data;
}

// close file
fclose ($fh);

// close directory
closedir($handle);

//echo "-- ALL DONE --";

?> 
I had to do this too, create a script that could search an ever-changing fileserver on our network.

I used ajax - you can see a demo of the app here: [font=Verdana]http://www.curtisbranum.com/portfolio/ajax.swf[/font]

anyway, I don't have the code with me, but I'll try to remember to post it when I'm at work tomorrow. To

speed things up, I have one script that builds a db table of all current file/folder names, so the php script is really just looking through the database table.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.