| re: Using implode with Windows UNC path names.
Shawn Campbell wrote:[color=blue]
> Terence <tk.lists@fastmail.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.txt
>>>
>>>This gives me the following warning:
>>>
>>>Warning: file("\\NH8516D02\Dpj302\weblog.txt") - No such file or
>>>directory in C:\apache\htdocs\bldcentral\viewlog.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\Dpj302\weblog.txt
>>will be translated to
>>\NH8516D02Dpj302weblog.txt
>>
>>use single quotes to prevent expansion of backslashes like so
>>
>>function_responsible_for_opening_the_file('\\NH8 516D02\Dpj302\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($StrSQL,$db);
> $product = mysql_fetch_array($result1);
>
> $logfile = sprintf("\\\\%s\\%s\\weblog.txt", $product["System"],
> $product["HostShare"]);
> $log_content = implode ('', file ($logfile));
> ========================
>
> When running this the error I get is:
>
> Warning: file("\\NH8516D02\Dpj302\weblog.txt") - No such file or
> directory in C:\apache\htdocs\bldcentral\viewlog.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. |