Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access a Mapped Driver, via opendir() OR exec()

    I'm needing help getting my PHP to read files on a Mapped Drive.
    My Server is Windows 2003.

    I can't even execute this simple bat file using
    PHP Code:
    <?php exec(); ?>
    function

    Code:
     
    copy "W:\*.csv" "Z:\WFM_XMLs\" /y
    Which would be my work around, that would just move the files from the Mapped drive, to a local hard drive.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    What is you're error when you attempt to read the directory?

    Edit:
    Oh yeah, and can you confirm if you're software (IIS or Apache), and whether you're doing this via web or via CLI?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    Bobafart (12-29-2008)

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Im sorry, details...

    Windows 2003 , Apache 2.2.10 PHP/5.2.6 with ActivePerl 5.10.0

    Loading it as a Web page, should I call php via CMD will that make it work.. im gonna try ..

    Im using this basic function to look at all the files in a directory, I know that only the files I need will be in this directory.

    PHP Code:
    <?php
    function dirList ($directory) {
     
    $results = array();
     
    $handler opendir($directory);
     while (
    $file readdir($handler)) {
      if (
    $file != '.' && $file != '..')
       
    $results[] = $file;
     }
     
    closedir($handler);
     return 
    $results;
    }
    ?>
    I call the function with... Which is a directory of a Mapped network drive, on another Windows 2003 Server. That requires a login, I have the drive saved user and pass and I have it auto reconnect.

    PHP Code:
    <?php
    $dirArray
    =dirList('W:/');
    ?>
    I just get the dumb errors

    Code:
    Warning:  opendir(W:/) [function.opendir]: failed to open dir: No error in C:\_web\dev_www\WFMpayroll\dir.php on line 13
    Warning:  readdir(): supplied argument is not a valid Directory resource in C:\_web\dev_www\WFMpayroll\dir.php on line 15
    Warning:  closedir(): supplied argument is not a valid Directory resource in C:\_web\dev_www\WFMpayroll\dir.php on line 23
    Having a second hard drive on the server with several 100 Gigs, I found that I could just move the files from the 'Shared Drive' to the 'Local Drive', which if I used the Z: drive in the call for the opendir function, it works. I made this work around...
    This line works in a .bat file ran on the Windows Server.

    Code:
    copy "W:\*.csv" "Z:\WFM_XMLs\" /y
    So I tried using PHP exec and shell_exec, but always get a blank array, I do IPCONFIG and I get all the returned information. I look into the folder just to see if it did it , but didnt echo, nope empty.

    PHP Code:
    <pre>
    <?php
    exec
    ('copy "W:\*.csv" "Z:\WFM_XMLs\" /y',$output);
    print_r($output);
    ?>
    </pre>
    I even tried ...
    PHP Code:
    exec('cmd /c [.bat location]'); 
    __

    The overall outcome is I need to get the files from anoter Windows Server, to the Windows Server the Apache/PHP is running on, then I need to loop through the files, see if the file name is in the database, if not import the CSV file into the database, else dont do anything with the file.

    Which I got a script that loops through searching my db for the file name inserting it if not found, importing it via LOAD DATA LOCAL INFILE

    __

    Everything works fine on the Local Hard drives, just not the Mapped.
    Oddly, I can't execute the .bat file via PHP. ?>?

    I think if I can just get PHP to move the files some how that would work out best

    I have Telnet enabled on the Target Windows Server, if that can help. Im attempting to think of a route myself. I may be able to enable Telnet on the other server.
    I can't relie on Windows Scheduler on this project.

  • #4
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think running the php script works, im going to try making exec run the php script.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Do try.
    I'm wondering if its just a permission problem. Remember that you're shares are combined most restrictive, so you're share permission must be set to a minimum of read, and the directory access must be at minimum read and traverse. I would probably give this privilege to Everybody, even if just to test it out.
    You should be able to see what process Apache is running under as well. It may be under a more restricted user that cannot read the provided directory. I find that a good way to test this is by using the absolute sharename path: \\yourserver\yourshare and see if you can connect. I would expect php to throw out no permission errors, but at least you know it can see it.

    Edit:
    Y'know, I'm curious if php is choking and considering this to be an external resource. If it is, you may be able to fix it by ensuring that allow_url_fopen is enabled in you're INI file.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    Bobafart (12-29-2008)

  • #6
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok it only works if I do it under windows, via run by PHP-cgi.exe

    Now if I use exec to call the php page like this.

    PHP Code:
    <pre>
    <?php
    exec
    ('cmd /c C:\php\php-5.2.6\php-cgi.exe C:\_web\dev_www\WFMpayroll\dir.php',$output);
    print_r($output);
    ?>
    </pre>
    I only get

    Code:
    Array(    [0] => X-Powered-By: PHP/5.2.6    [1] => Content-type: text/html    [2] =>     [3] =>     [4] => Array    [5] => (    [6] => )    [7] =>     [8] =>     [9] => )

    So I think I figured out whats up, from watching all of these script run via CLI

    I think when I have a web page use exec, it isn't going to walk for it to end before it goes any and give me output. So it ends running the script. if thats the cause, can i make it keep going

  • #7
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now when you say set the premissions which 'Folder' do you mean and On which server.

    When I set premissions on the Mapped Drive, which is direct to the folder that holds the CSV files. I can only add users that show up on the HOST SERVER. Iv added everyone and system, set to FULL rights. Nothing changed.

    I made sure those same premissions were on the HOST SERVER

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Ok it only works if I do it under windows, via run by PHP-cgi.exe
    Do you mean IIS?
    If so, it definitely sounds like a permissions problem.

    Sounds like you're permissions are set fine. Often its a problem on the host server end (since everything appears well on our ends). Best I know, the actual share permissions are default for full control on everyone, so thats fine, no reason to change those.

    I'll check back later, I've got some work to finish in the next hour so I can go home :P
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    Bobafart (12-29-2008)

  • #9
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Do you mean IIS?
    If so, it definitely sounds like a permissions problem.

    Sounds like you're permissions are set fine. Often its a problem on the host server end (since everything appears well on our ends). Best I know, the actual share permissions are default for full control on everyone, so thats fine, no reason to change those.

    I'll check back later, I've got some work to finish in the next hour so I can go home :P

    No i dont have IIS installed at all.
    Im using apache, loading php via
    Code:
    LoadModule php5_module "C:/php/php-5.2.6/php5apache2_2.dll"
    PHPIniDir "C:/php/php-5.2.6"
    when i say php-cgi.exe, what I did is right click the .php file open with and tried each of the 3, until it worked, php.exe, php-cgi.exe, php-win.exe


    php.ini has allow_url_fopen on no change was needed

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I would have thought the cli ones would work too (since they are also run as you're user).
    I'm not sure what the problem is, and I don't have quite a configuration that allows me to test it out either.
    To me, it sounds like it can't access the path via Apache.
    Try this out, open you're services (services.msc I believe it is), find Apache and change the login credentials to a specific account. Even for testing, just put it as an administrator or any standard account you can access (don't leave it as an admin of course!). Restart it, see if that fixes it.

    When I used to have a server setup with both IIS and Apache, I used IISUser for both so my apache logged in as IISUser and I had no trouble with access.

    Edit:
    I'll poke around the net in a little while too to see if I can't find this exact situation.
    Last edited by Fou-Lu; 12-25-2008 at 05:45 AM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #11
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no difference with Administrator as the apache runner, I even rebooted.

    I even followed .. http://httpd.apache.org/docs/2.0/platform/windows.html

    Running Apache as a ServiceNothing made any effect..

    Im still finding it strange exec() isn't fixing the issue, well it is, if I open with php directly, instead of using the browser.

    But I need to be able to remotely do this.

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yeah I'm a little at a loss myself.
    There are some extra things you can try. I was actually directed to this from a google search, but check out the user comments for opendir on the PHP website. The first one looks like it fits you're problem to the 'T'. I was close if it does turn out to work
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #13
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, so I finaly was able to set it as (Administrator) and rebooted, and it was able to pull the opendir via
    PHP Code:
    $dirArray=dirList('//INTERNAL IP/xml'); 
    Then I setup a new user, made sure all directories had acces, I restarted the service, all my old apps, ALIAS's worked, but not the script.
    So I rebooted, the new user wouldnt start the service, kept saying syntax error line 117, and DocumentRoot (which is line 117) must be a directory, [these errrors were in event viewer] . The access rights existed correctly for the new user.

    There server is external also, so there is no way I can make Administrator run the service. But I need this solution, which I had with Admin.

    What am I doing wrong here. I have complete control over both servers. This is a (intranet) setup, with them both having external IPs

  • #14
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Sounds like you're getting closer.
    I'm about 80% sure that documentRoot error you're getting is one I had before as well. Windows doesn't like having no drive to map to, and actually halts you're apache if its not available. I was doing this with a flash stick when I was in school and mounting it on a linux computer and mapping it on my windows. I found out when it wasn't available it stopped my apache on windows (though just triggered an error on linux).

    With you're administrator account, is its domain the same (or higher) as the remote share? With the user account you created, did you make sure that it has act as a part of the OS and Login as a service privileges (both of these I believe are group policies)?

    All and all it just *sounds* like you cannot access the share as you're user OR the Apache service is loading before you're tcpip, afd, svchost for netsvcs, possibly lanmanworkstation (or other network redirection service) or rpcss services. Sadly these dependancies are not my strong point, but I believe you're requiring the tcpip, afd and lanmanworkstation as dependancies before you can run you're apache service and access remote shares.
    You'd think that this would be easier by just mapping it eh >.<

    Oh, I'm going to move this thread too, since its more of a config problem then a php problem. I'll leave a redirect too.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #15
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The Document Error I was getting was all lies the document root is on a local hard drive
    Code:
    DocumentRoot "C:/_web/www"
    And like I said the user I made to run apache, it had access to that drive, It had all the access to Run as OS and Log on as Service.
    I had the network share Mapped, and had it auto reconnect.

    when I use administrator my script works by going to the //INTERNAL IP/share . but still not the mapped drive, which is ok.
    Maybe I need to login as that user and log into the shared folder and have it save the password to it also.



    Now when you said domain. there isnt one other that the computers names. We dont have Active Directory. Both the servers on are the same subnet though.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •