Using implode with Windows UNC path names.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn Campbell

    #1

    Using implode with Windows UNC path names.

    Here's my scenario:

    I'm creating a build environment with one system acting as the main
    build dispatcher and other systems as the build hosts. On the main
    build system I have Apache, MySQL and PHP installed and I'm building a
    website that will allow people to view/start/etc. builds.

    I'm trying to get PHP to implode a log file that resides on one of the
    host builds systems. I have the host and and the share, so what I'm
    passing into the implode command is:

    \\NH8516D02\Dpj 302\weblog.txt

    This gives me the following warning:

    Warning: file("\\NH8516D 02\Dpj302\weblo g.txt") - No such file or
    directory in C:\apache\htdoc s\bldcentral\vi ewlog.php on line 21

    Question:

    Is there a way for PHP to open a file on a different system from a
    folder that has been shared? I'm not too worried about security as
    this is an internal site to the company.

    Thanks for any help!

    -Shawn Campbell
  • Terence

    #2
    Re: Using implode with Windows UNC path names.

    Shawn Campbell wrote:[color=blue]
    > Here's my scenario:
    >
    > I'm creating a build environment with one system acting as the main
    > build dispatcher and other systems as the build hosts. On the main
    > build system I have Apache, MySQL and PHP installed and I'm building a
    > website that will allow people to view/start/etc. builds.
    >
    > I'm trying to get PHP to implode a log file that resides on one of the
    > host builds systems. I have the host and and the share, so what I'm
    > passing into the implode command is:
    >
    > \\NH8516D02\Dpj 302\weblog.txt
    >
    > This gives me the following warning:
    >
    > Warning: file("\\NH8516D 02\Dpj302\weblo g.txt") - No such file or
    > directory in C:\apache\htdoc s\bldcentral\vi ewlog.php on line 21
    >
    > Question:
    >
    > Is there a way for PHP to open a file on a different system from a
    > folder that has been shared? I'm not too worried about security as
    > this is an internal site to the company.
    >
    > Thanks for any help!
    >
    > -Shawn Campbell[/color]


    use single quotes to refer to the file name. If you use double quotes,
    then PHP will expand the backslash character to mean that it is not a
    back slash, but an escape. so
    \\NH8516D02\Dpj 302\weblog.txt
    will be translated to
    \NH8516D02Dpj30 2weblog.txt

    use single quotes to prevent expansion of backslashes like so

    function_respon sible_for_openi ng_the_file('\\ NH8516D02\Dpj30 2\weblog.txt');

    Comment

    • Shawn Campbell

      #3
      Re: Using implode with Windows UNC path names.

      Terence <tk.lists@fastm ail.fm> wrote in message news:<3f1f8ec3$ 1@cicada>...[color=blue]
      > Shawn Campbell wrote:[color=green]
      > > Here's my scenario:
      > >
      > > I'm creating a build environment with one system acting as the main
      > > build dispatcher and other systems as the build hosts. On the main
      > > build system I have Apache, MySQL and PHP installed and I'm building a
      > > website that will allow people to view/start/etc. builds.
      > >
      > > I'm trying to get PHP to implode a log file that resides on one of the
      > > host builds systems. I have the host and and the share, so what I'm
      > > passing into the implode command is:
      > >
      > > \\NH8516D02\Dpj 302\weblog.txt
      > >
      > > This gives me the following warning:
      > >
      > > Warning: file("\\NH8516D 02\Dpj302\weblo g.txt") - No such file or
      > > directory in C:\apache\htdoc s\bldcentral\vi ewlog.php on line 21
      > >
      > > Question:
      > >
      > > Is there a way for PHP to open a file on a different system from a
      > > folder that has been shared? I'm not too worried about security as
      > > this is an internal site to the company.
      > >
      > > Thanks for any help!
      > >
      > > -Shawn Campbell[/color]
      >
      >
      > use single quotes to refer to the file name. If you use double quotes,
      > then PHP will expand the backslash character to mean that it is not a
      > back slash, but an escape. so
      > \\NH8516D02\Dpj 302\weblog.txt
      > will be translated to
      > \NH8516D02Dpj30 2weblog.txt
      >
      > use single quotes to prevent expansion of backslashes like so
      >
      > function_respon sible_for_openi ng_the_file('\\ NH8516D02\Dpj30 2\weblog.txt');[/color]

      The php code does have it correctly. Here's the snippet from my code.


      =============== =========
      $db = mysql_connect(" localhost", "root");
      mysql_select_db ("bldcentral",$ db);

      $StrSQL = "SELECT * FROM products WHERE ProductID='$pid ';";
      $result1 = mysql_query($St rSQL,$db);
      $product = mysql_fetch_arr ay($result1);

      $logfile = sprintf("\\\\%s \\%s\\weblog.tx t", $product["System"],
      $product["HostShare"]);
      $log_content = implode ('', file ($logfile));
      =============== =========

      When running this the error I get is:

      Warning: file("\\NH8516D 02\Dpj302\weblo g.txt") - No such file or
      directory in C:\apache\htdoc s\bldcentral\vi ewlog.php on line 21

      It looks more like Apache will not allow a file from another system to
      be opened in this manner.

      Any other suggestions?

      Comment

      • Terence

        #4
        Re: Using implode with Windows UNC path names.

        Shawn Campbell wrote:[color=blue]
        > Terence <tk.lists@fastm ail.fm> wrote in message news:<3f1f8ec3$ 1@cicada>...
        >[color=green]
        >>Shawn Campbell wrote:
        >>[color=darkred]
        >>>Here's my scenario:
        >>>
        >>>I'm creating a build environment with one system acting as the main
        >>>build dispatcher and other systems as the build hosts. On the main
        >>>build system I have Apache, MySQL and PHP installed and I'm building a
        >>>website that will allow people to view/start/etc. builds.
        >>>
        >>>I'm trying to get PHP to implode a log file that resides on one of the
        >>>host builds systems. I have the host and and the share, so what I'm
        >>>passing into the implode command is:
        >>>
        >>>\\NH8516D02\ Dpj302\weblog.t xt
        >>>
        >>>This gives me the following warning:
        >>>
        >>>Warning: file("\\NH8516D 02\Dpj302\weblo g.txt") - No such file or
        >>>directory in C:\apache\htdoc s\bldcentral\vi ewlog.php on line 21
        >>>
        >>>Question:
        >>>
        >>>Is there a way for PHP to open a file on a different system from a
        >>>folder that has been shared? I'm not too worried about security as
        >>>this is an internal site to the company.
        >>>
        >>>Thanks for any help!
        >>>
        >>>-Shawn Campbell[/color]
        >>
        >>
        >>use single quotes to refer to the file name. If you use double quotes,
        >>then PHP will expand the backslash character to mean that it is not a
        >>back slash, but an escape. so
        >>\\NH8516D02\D pj302\weblog.tx t
        >>will be translated to
        >>\NH8516D02Dpj 302weblog.txt
        >>
        >>use single quotes to prevent expansion of backslashes like so
        >>
        >>function_resp onsible_for_ope ning_the_file(' \\NH8516D02\Dpj 302\weblog.txt' );[/color]
        >
        >
        > The php code does have it correctly. Here's the snippet from my code.
        >
        >
        > =============== =========
        > $db = mysql_connect(" localhost", "root");
        > mysql_select_db ("bldcentral",$ db);
        >
        > $StrSQL = "SELECT * FROM products WHERE ProductID='$pid ';";
        > $result1 = mysql_query($St rSQL,$db);
        > $product = mysql_fetch_arr ay($result1);
        >
        > $logfile = sprintf("\\\\%s \\%s\\weblog.tx t", $product["System"],
        > $product["HostShare"]);
        > $log_content = implode ('', file ($logfile));
        > =============== =========
        >
        > When running this the error I get is:
        >
        > Warning: file("\\NH8516D 02\Dpj302\weblo g.txt") - No such file or
        > directory in C:\apache\htdoc s\bldcentral\vi ewlog.php on line 21
        >
        > It looks more like Apache will not allow a file from another system to
        > be opened in this manner.
        >
        > Any other suggestions?[/color]

        Well I can tell you that apache doesn't limit PHP's file access other
        than by virtue of the user that the apache process is running as.
        Anyhow, if your apache's [run-as] user doesn't have permissions to a
        particular file resource, then you should get a permissions error.

        I've just built a PHP application running on win2k with apache and I've
        been accessing files on a UNC file share with no problems at all.

        just give the single quotes a try and let me know how you go.


        Comment

        Working...