Page 1 of 1
Searching Network Drives
Posted: Thu Jun 28, 2007 9:47 pm
by slonison
Ok here's the deal. I go to a college where there are a few servers on campus... What I want to do is search these servers with php and add certain traits about them to a mysql database. There's no problem with the adding them to the database so long as I have the file name.
The thing I'm having a problem with is actually finding the files.
Now I tried this code for my server.
Code: Select all
<?php
$Array = glob('\\\\myserver\\Shared\\*', GLOB_ONLYDIR);
while(list ($key,$value) = each($Array))
{
echo $key . ' : ' . $value . '<br />';
}
?>
Indexing went just fine. But when I tried...
Code: Select all
<?php
$Array = glob('\\\\servername\\Shared\\*', GLOB_ONLYDIR);
while(list ($key,$value) = each($Array))
{
echo $key . ' : ' . $value . '<br />';
}
?>
It didn't work...I know I have permission to the folder because I access files from there all the time. Not to mention, I'm not the only search engine on the campus, there's another which does mysql databases as well.
The first code returns
Code: Select all
0 : \\myserver\Shared\Comedy
1 : \\myserver\Shared\Emulation
2 : \\myserver\Shared\Movies
3 : \\myserver\Shared\New Releases
4 : \\myserver\Shared\OST
5 : \\myserver\Shared\Programs
6 : \\myserver\Shared\TV Shows
While the second set of code returns a blank white page.
Yes, I've searched through the forums but never got an answer that would work. Thanks alot.
Not to mention, but this only searches the folder I specifiy next to the servername... what I'm actually looking for is a script that can grab all of the shared folders by using just the \\\\servername\* command.
Re: Searching Network Drives
Posted: Thu Jun 28, 2007 10:03 pm
by volka
slonison wrote:I know I have permission to the folder because I access files from there all the time.
Are you sure this script runs with your account's permissions? If you run it through a webserver it might be another account.
Posted: Thu Jun 28, 2007 10:11 pm
by slonison
ok let me rephrase... Whenever we access the servers... we basically jsut go to Start->Run->'\\servername
this basically just opens windows explorer with the files displayed in the folder where I can drag and drop.
Posted: Thu Jun 28, 2007 10:15 pm
by volka
Let's try another question: Exactly how do you invoke the php script?
Posted: Thu Jun 28, 2007 10:26 pm
by slonison
I put the script online and just type into my browser [mozilla:firefox] the URL of the file.
Posted: Thu Jun 28, 2007 10:27 pm
by volka
Meaning: You are running the script through a webserver. The webserver process might work under another account not having the permissions needed to access the network shares.
Posted: Thu Jun 28, 2007 10:35 pm
by slonison
How do I run it in such a way that it has the same permissions sent as when I access it through Run.
The server is in my home so I have access to everything on it.
Posted: Fri Jun 29, 2007 12:28 am
by volka
In case you're running an apache webserver on a win32 machine you might be interested in
http://httpd.apache.org/docs/2.2/platfo ... tml#winsvc
Posted: Fri Jun 29, 2007 12:36 am
by slonison
Yes, I think that's the case because the I installed xampp on a Windows XP Professional Edition. So I'll take a look at the article.
Posted: Mon Jul 02, 2007 1:09 am
by slonison
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ok i've read the article but I still don't understand how I can make this code work...
Forgive, me I don't know much about web development but I'm more than willing to learn. I've been trying this...
Code: Select all
<?
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could Not Connect: ' . mysql_error());
}
mysql_select_db("bbb",$con);
$sql="TRUNCATE TABLE server";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
$servername = "//servername/Shared/";
$dir0 = opendir($servername);
$i=1;
while (($file = readdir($dir0)) != false)
{
if($file != "." && $file != "..") //If the file isn't root the directory
{
if($file != "." && $file != "..")
{
$path1 = $servername . $file;
$dir1 = opendir($path1);
while (($file1 = readdir($dir1)) != FALSE)
{
if($file1 != "." && $file1 != "..")
{
$path2 = $path1 . "/" . $file1;
$dir2 = opendir($path2);
while (($file2 = readdir($dir2)) != FALSE)
{
if(stristr($file2, ".") != FALSE && $file2 != "." && $file2 != ".." && $file2 != "Thumbs.db")
{
$path3 = "file:///" . $path2 . "/";
$size=substr(filesize($path2."/".$file2)/1000000,0,4) . " MB";
$ext=substr($file2,-4);
$sql="INSERT INTO server (Name, SubDir1, SubDir2, SubDir3, Path, Size, Type) VALUES ('$file2','$file','$file1','','$path3','$size','$ext')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo $file . " " . " " . $file2 . "<font color=red> Added</font>". "<br />";
}
}
}
}
}
}
}
closedir($dir0);
mysql_close($con);
?>
The code only works if servername is the name of the computer that the server is run off of...
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Mon Jul 02, 2007 4:15 am
by volka
Have you changed to account settings for the webserver from LocalSystem to something that has access to the network?
http://httpd.apache.org/docs/2.2/platform/windows.html#winsvc wrote:By default, all Apache services are registered to run as the system user (the LocalSystem account). The LocalSystem account has no privileges to your network via any Windows-secured mechanism, including the file system, named pipes, DCOM, or secure RPC.
Posted: Mon Jul 02, 2007 11:40 pm
by slonison
Ok, I understand that it's the credentials and stuff from my apache setup, but can you inform me how to change these settings?
Posted: Tue Jul 03, 2007 12:26 am
by feyd
Follow the link volka kindly provided. Read the section under his quoted text.
Posted: Tue Jul 03, 2007 8:02 am
by slonison
Ok I'm sorry if it's getting annoying to help me out. But I'm still having trouble understanding what they have written.
1. Create a normal domain user account, and be sure to memorize its password.
Where and how do I do this? Do I do this the same way as creating a new user account for the computer?
2. Grant the newly-created user a privilege of Log on as a service and Act as part of the operating system. On Windows NT 4.0 these privileges are granted via User Manager for Domains, but on Windows 2000 and XP you probably want to use Group Policy for propagating these settings. You can also manually set these via the Local Security Policy MMC snap-in.
3. Confirm that the created account is a member of the Users group.
4. Grant the account read and execute (RX) rights to all document and script folders (htdocs and cgi-bin for example).
5. Grant the account change (RWXD) rights to the Apache logs directory.
6. Grant the account read and execute (RX) rights to the Apache.exe binary executable.
No clue at all how to do the rest. The group policy thing I took a look at but it seems really complicated, and if somebody on the devnetwork forums know, I'd rather not go in blindly and change something I shouldn't.
Thanks