0

I am working on a php code as shown below in which I want to access network drive folder (music) using credentials in php. The credentials is being set because I want to give the full access only to a particular user.

$src_dir = '\\\INVEST-OP-001\test\music'; // Line#A

The full permission/access of music folder is given to the following credentials:

username : 'mickeymouse'
password : 'helloworld'

Problem Statement:

I am wondering what changes I should make in the php code at Line#A so that I can access the music folder using credentials in php.

flash
  • 1,455
  • 11
  • 61
  • 132

1 Answers1

1

This works for me:

<?php

$user = 'mickeymouse';
$password = 'helloworld';

exec('net use "\\\INVEST-OP-001\test\music" /user:"'.$user.'" "'.$password.'" /persistent:no');
$files = scandir('\\\INVEST-OP-001\test\music');
echo '<pre>';
print_r($files);

exec('net use "\\\INVEST-OP-001\test\music" /delete /yes');
Bruno Leveque
  • 2,647
  • 2
  • 23
  • 33
  • /user is /helloworld ? – flash May 28 '19 at 20:04
  • like this `exec('net use "\\\INVEST-OP-001\test\music" /mickeymouse:"'.$mickeymouse.'" "'.$hellworld.'" /persistent:no');` – flash May 28 '19 at 20:05
  • No, `/user:` has to remain as is. Final result will be `net use "\\\INVEST-OP-001\test\music" /user:mickeymouse helloworld /persistent:no` – Bruno Leveque May 28 '19 at 20:06
  • What this command do `exec('net use "\\\INVEST-OP-001\test\music" /delete /yes');` ? It disconnects the connection established for that credentials ? – flash May 29 '19 at 15:02
  • Yes, exactly, like when you disconnect a network drive in the Windows explorer. – Bruno Leveque May 29 '19 at 15:40
  • hope all is well. I have a similar [question](https://stackoverflow.com/questions/56430459/how-to-convert-mp4-files-into-mp3-on-button-click-using-ffmpeg-php) I am wondering if you can have a look. – flash Jun 03 '19 at 16:14