#native_company# #native_desc#
#native_cta#

Samba filesystem mounting

By Willem Vooys
on January 29, 2003

Version: 1.14

Type: Function

Category: File Management

License: GNU General Public License

Description: These functions let you easily mount a (windows) network share on your linux box.

function smb_connect($share, $localdir, $username="", $password="")
{
  //this function is dependent of 'is_mounted()', also found here
  //remember that mount can only be executed by the super-user, 
  //unless the mount command is already in etc/fstab with the 
  //'user' option enabled:see the manual entry for mount and/or fstab
  
  $umount="umount ".$localdir;
  $smbmount="smbmount ".$share." ". $localdir;

  if($username != "")
  {
   $smbmount.=" -o username=".$username;
   if($password != "")
     $smbmount.=",password=".$password;
  }
  
  if(is_mounted($share))
    RETURN TRUE;
  else
  {
    exec($umount); //just to be sure
    exec($smbmount); //try to mount it
    
    if(is_mounted($share))
      RETURN TRUE;
    else
      RETURN FALSE;
  }
}

function smb_disconnect($dir)
{
  exec("umount ".$dir);
}

function is_mounted($device)
{
  exec("mount", $mounted);
  for($i=0;$i<count($mounted);$i++)
  {
    $this_device=explode(" ", $mounted[$i]);
    if($this_device[0] == $device)
      $found=TRUE;
  }
  if($found)
    RETURN TRUE;
  else
    RETURN FALSE;
}