-1

I am trying to access image from network drive which is connected to my machine. But i am unable to access it using php. I mapped it using net use command still i am unable to accees it. Please help me out.

 if($fh=opendir('\\\\F:')) {
 while (false !== ($fi =readdir($fh))) {
 echo "$fi\n";
 }
 }

Even i tried below code also

   <?php
    $path = '\\Z:';

    $user = "administrator";
    $pass = "dev";
    $drive_letter = "Z";

    system("net use ".$drive_letter.": \"".$path."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1");
    $location = $drive_letter.":/";

    if ($handle = opendir($location)) {
       while (false !== ($entry = readdir($handle))) {
       echo "$entry"; echo "<br>";
       } 
       closedir($handle);
     }
     ?>        

1 Answers1

0

It's my opinion that the problem is linked with the user that run Apache, because you have a mapped drive with credential on your user account that it's different from that run Apache.

First, make Apache run as Administrator and then run net use command inside the script:

<?php
$path = '\\\\younetworkdrive\\yoursharedfolder'; 

$user = "mickeymouse";
$pass = "waltdisney";
$drive_letter = "Z";

system("net use ".$drive_letter.": \"".$path."\" ".$pass." /user:".$user." /persistent:no>nul 2>&1");
$location = $drive_letter.":/";

if ($handle = opendir($location)) {
    while (false !== ($entry = readdir($handle))) {
 echo "$entry";
    } 
    closedir($handle);
}

I just tried it....it's work

An4Th3mA
  • 39
  • 2