Hello,
I am new to PHP, but hoping all of you experts out there can help me get better. I have been granted the task of improving our company intranet, and I am trying to give a directory listing of a folder on our network.
I would like to give access to files in this directory for viewing, printing, etc, but not allow them to change them. (also having troubles with permissions here but that is another issue)
Nothing like diving head first into the deep end, with sharks, to learn how to swim! So please bear with me if some of this is obvious or if I am asking something stupid.
With the help of this site I have gotten everything to work except for a couple quarks I can not figure out.
The first thing my page is to do is check if the drive to the directory is mapped. If it isn't I want it to map the drive and then go through a loop to display the contents. A fairly simple 2 step process.
Doing some testing I have gotten both of these tasks to work separately on their own, however things get weird when I tried to combine them.
In the morning when the drive is not yet mapped, when I pull up the page it says it can not read the drive. In other words it seems to skipping the mapping of the drive and going right to the createDir when the drive is not yet mapped.
Here is where it gets weird. If I refresh the page, it works... It maps the drive and lists everything like it should.
I am lost on why it would act this way.
Actually, this just came to me - could it be a cache issue?
Any help is appreciated!
<?php
/* Make sure drive is mapped to directory */
$letter='Q';
$drive= $letter.':\\';
/* Create COM object */
$WshNetwork = new COM("WScript.Network");
if(is_dir($drive))
{
/* Drive is currently mapped, do nothing */
}
else
{
/* Map the drive */
$WshNetwork->MapNetworkDrive( "$letter:" , '\\\server\\folder' , FALSE, 'domain\\user' , 'password' ) or die( 'Unable to map drive');
}
$path = '//server/folder/';
/*$path = 'Q:\\'; */
function createDir($path = '.')
{
if ($handle = opendir($path))
{
echo "<ul>";
while (false !== ($file = readdir($handle)))
{
if (is_dir($path.$file) && $file != '.' && $file !='..')
printSubDir($file, $path, $queue);
else if ($file != '.' && $file !='..')
$queue[] = $file;
}
printQueue($queue, $path);
echo "</ul>";
}else
{
echo "Error reading directoy ".$path;
}
}
cont'd...........