note 90373 added to function.opendir
| From: | DaveRandom at osu1 dot php dot net | Date: | Sat, 18 Apr 2009 16:08:40 +0000 |
| Subject: | note 90373 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153471@lists.php.net to get a copy of this message | ||
A couple of notes on Matt's posts on Windows Network Drives:
Since the system() command writes the output of the executed shell command straight to the output
buffer, if you wish to hide the return of the mapping command (i.e. "The command completed
succesfully" or an error message) from a web browser, you need to alter the command that is
sent to the shell so that the output of that command is hidden.
You probably thinking "why not just use exec()?", and it's a reasonable question, but
for some reason it doesn't always work - I guess it's another NT user permissions issue.
If you want to guarantee you app will work with no messing around on the host system, use the
system() command.
In the Windows command shell, you can hide the output of a command by sending both the output (1)
and error (2) messages to "nul" using pipes, in other words ">nul
2>&1" on the end of the command. The username and password order in the "net
use..." command needs switching in Matt's post.
Here (http://networkm.co.uk/static/drive.html) is a function I wrote to dynamically choose which
drive letter to use, based on what is currently mapped and accessible to PHP.
<?php
// Define the parameters for the shell command
$location = "\\servername\sharename";
$user = "USERNAME";
$pass = "PASSWORD";
$letter = "Z";
// Map the drive
system("net use ".$letter.": \"".$location."\"
".$pass." /user:".$user." /persistent:no>nul 2>&1");
// Open the directory
$dir = opendir($letter.":/an/example/path")
...
?>
----
Server IP: 92.48.74.199
Probable Submitter: 87.127.188.153
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- https://master.php.net/note/edit/90373
Del: integrated -- https://master.php.net/note/delete/90373/integrated
Del: useless -- https://master.php.net/note/delete/90373/useless
Del: bad code -- https://master.php.net/note/delete/90373/bad+code
Del: spam -- https://master.php.net/note/delete/90373/spam
Del: non-english -- https://master.php.net/note/delete/90373/non-english
Del: in docs -- https://master.php.net/note/delete/90373/in+docs
Del: other reasons-- https://master.php.net/note/delete/90373
Reject -- https://master.php.net/note/reject/90373
Search -- https://master.php.net/manage/user-notes.php