简体   繁体   中英

How to access images or files from the network drive in PHP

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);
     }
     ?>        

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM