note 73576 added to ref.dir
| From: | oscararzola at gmail dot com | Date: | Thu, 01 Mar 2007 22:20:27 +0000 |
| Subject: | note 73576 added to ref.dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124000@lists.php.net to get a copy of this message | ||
<?php
class muestraArchivos
{
//constructor
var $directorio;
var $archivos;
var $exten = array();
public function setDir($dameDir)
{
$this->directorio = dir($dameDir);
}
private function leeDir()
{
return $this->directorio->read();
}
public function addExtension($ex)
{
if($this->getNumRows() > 0)
{
return array_push($this->exten, $ex);
}
else
{
return $this->exten[] = $ex;
}
}
public function showDir()
{
//echo $this->directorio->path."<br>";
//hacemos un while para sacar los archivos del directorio
while($this->archivos = $this->leeDir())
{
//eliminamos los puntitos nacos
if($this->archivos != "." && $this->archivos != "..")
{
if($this->checaExtension($this->archivos))
{
echo $this->archivos."<br>\n";
}
}
}
}
public function showDirCadena()
{
$j=0;
//hacemos un while para sacar los archivos del directorio
while($this->archivos = $this->directorio->read())
{
//eliminamos los puntitos nacos
if($this->archivos != "." && $this->archivos != "..")
{
if($this->checaExtension($this->archivos))
{
$j++;
echo "file$j=".$this->archivos."&";
}
}
}
}
public function showDirXml()
{
$j=0;
header("Content-type: text/xml\n");
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
echo "<archivos>\n";
//hacemos un while para sacar los archivos del directorio
while($this->archivos = $this->directorio->read())
{
//eliminamos los puntitos nacos
if($this->archivos != "." && $this->archivos != "..")
{
if($this->checaExtension($this->archivos))
{
$j++;
echo "<archivo>".$this->archivos."</archivo>\n";
}
}
}
echo "</archivos>";
}
public function closeDir()
{
$this->directorio->close;
}
private function checaExtension($archivo)
{
$extensiondestripada = split("[.]",$archivo);
for($n=0; $n<$this->getNumRows();$n++)
{
//si coincide con alguna extension valida imprimimos
if(!strcmp($extensiondestripada[1],$this->exten[$n]))
{
$salida = 1;
break;
}
else
{
$salida = 0;
}
}
return $salida;
}
private function getNumRows()
{
return count($this->exten);
}
}
?>
<?php
include('dir.php');
$test = new muestraArchivos;
$test->setDir("jpgs");
$test->addExtension("jpg");
$test->showDirCadena();
$test->closeDir();
?>
----
Server IP: 69.147.83.197
Probable Submitter: 189.140.214.240
----
Manual Page -- http://www.php.net/manual/en/ref.dir.php
Edit -- https://master.php.net/note/edit/73576
Del: integrated -- https://master.php.net/note/delete/73576/integrated
Del: useless -- https://master.php.net/note/delete/73576/useless
Del: bad code -- https://master.php.net/note/delete/73576/bad+code
Del: spam -- https://master.php.net/note/delete/73576/spam
Del: non-english -- https://master.php.net/note/delete/73576/non-english
Del: in docs -- https://master.php.net/note/delete/73576/in+docs
Del: other reasons-- https://master.php.net/note/delete/73576
Reject -- https://master.php.net/note/reject/73576
Search -- https://master.php.net/manage/user-notes.php