Re: popen, a funny thing
| From: | Mathias Breiner | Date: | Sun, 15 Oct 2000 19:55:42 +0000 |
| Subject: | Re: popen, a funny thing | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-3250@lists.php.net to get a copy of this message | ||
Hi,
your script works on my pc, but not the way desired, no matter if I use the
browser or command-line. It produces following output:
...
<option value=1> [..]</option>
<option value=2> TEST~1.HTM</option>
<option value=3> HOFMANN1.HTM SORTTE~1.PHP
</option>
<option value=4> LEER~1.HTM</option>
<option value=5> IMG_GD.PHP</option>
<option value=6> RAND~1.PHP</option>
<option value=7> COUNTER.PHP</option>
<option value=8>
</option>
<option value=9>
</option>
<option value=10> ENTITIES.PHP IMEXPL~1.PHP TYPE~1.PHP</option>
<option value=11> CHOP~1.PHP</option>
...
(The tildes result from running W95.)
Maybe it's so weird because you can't rely on the DIR-command.
Another problem of your script is that filenames with spaces are 'splitted'.
Some time ago, I wrote following script for getting all files in a directory
(and even subdirs):
function seekdir($dir) {
$handle = opendir($dir);
while ($file = readdir($handle)) {
if(($file != '.') && ($file != '..')) {
if(is_dir($dir.$file)) seekdir($dir.$file.'/');
else {
.....
}
}
}
closedir($handle);
One advantage is that it also works on UNIX.
Be sure to use a Linux-style path, so in your case you would have to call
the function with
seekdir('/inetpub/wwwroot/');
(works only if the script can also be found on c:)
- Mathias
-----------------------------------
Mathias Breiner
76744 Wörth / Germany
mathiasbr@web.de
http://latrine.piff.de/
-----------------------------------
----- Original Message -----
From: Hugo Alexandre A. S. Dias <anikin@alfarrabio.di.uminho.pt>
To: <php-windows@lists.php.net>
Sent: Saturday, October 14, 2000 12:02 PM
Subject: popen, a funny thing
> I'm having a problem.
> when i run this script it has two diferent outputs, one in the browser and
> other in command line:
> The script is this:
> <body>
>
> <select name="files">
> <?
> $path="c:\\inetpub\\wwwroot";
> $cmd="dir /w " .$path;
> $fp=popen($cmd,"r");
> if ($fp==false){
> echo "ERRO";
> } else{
> $linha=fgets($fp,80);
> $linha=fgets($fp,80);
> $linha=fgets($fp,80);
> $linha=fgets($fp,80);
> $linha=fgets($fp,80);
> $j=1;
> $fn=array();
> while (!feof($fp)){
> $linha=fgets($fp,80);
> if ($linha[0]!=' '){
> $fn=split(' +',$linha);
> for(;$i=next($fn);){ ?> <option value=<? echo $j++; ?>><? echo $i;
> ?></option>
> <? }
> }
> }
> }
>
> pclose($fp);
> ?>
> </select>
> </body>
>
> When i run in the browser the output is:
> <body>
>
> <select name="files">
> </select>
> </body>
>
> but when i run in command line, the output is:
> C:\Inetpub\wwwroot\default>\php\php teste.php
> X-Powered-By: PHP/4.0.2
> Content-type: text/html
>
> <body>
>
> <select name="files">
> <option value=1>[..]</option>
> <option value=2>[ps2portugal]</option>
> <option value=3>[lusotour]</option>
> <option value=4>[default]
> </option>
> <option value=5>[Lome]</option>
> <option value=6>[Editor]</option>
> <option value=7>[NovoEditor]</option>
> <option value=8>teste.pl
> </option>
> <option value=9>lome.sql</option>
> <option value=10>README.txt</option>
> <option value=11>Editor.zip</option>
> <option value=12>
> </option>
> </select>
> </body>
>
> The goal of this script is to build a combo box for selecting all the
files
> in a directory.
>
> I hope that anyone can tell me the problem, cause i can't figure it out :(
> --------------------------------------------------------------------------
--
> Hugo Alexandre Almeida Soares Dias MNI.pt
> E-mail: anikin@alfarrabio.di.uminho.pt Web-programmer
> HomePage: http://paginas.teleweb.pt/~hasd/
> http://www.mni.pt/
> http://www.saudenainternet.pt/
> http://www.listamedica.pt
> --------------------------------------------------------------------------
--
>
>