Revision [3616]

This is an old revision of ListfilesAction made by ChristianBarthelemy on 2004-12-22 17:02:45.

 

An action to list the files attached to the WikiPage


This is another transformation of the files action from Mod015fFilesAction (check also the FilesManagementHandler).
It allows to get the links to the attached files but not to upload nor to delete any.

This action uses the handlers files.xml.php from the FilesAction. Once the handler is in place you need to create the below listfiles.php and place it in the actions folder:
<?php
if ($download <> '') {

        // link to download a file
        if ($text == '') $text = $download;
        echo "<a href=\"".$this->href('files.xml',$this->GetPageTag(),'action=download&file='.urlencode($download))."\">".$text."</a>";

} elseif ($this->page AND ($this->method <> 'print.xml') AND ($this->method <> 'edit')) {

        // upload path
        if ($this->config['upload_path'] == '') $this->config['upload_path'] = 'files';
        $upload_path = $this->config['upload_path'].'/'.$this->GetPageTag();
        if (is_dir($upload_path)) {

            // form
            $result = "<form action=\"".$this->href()."\" method=\"post\" enctype=\"multipart/form-data\">\n";
            if (!$this->config["rewrite_mode"]) $result .= "<input type=\"hidden\" name=\"wakka\" value=\"".$this->MiniHref()."\">\n";
            echo $result;

            echo $this->FormClose();

            // uploaded files
            $dir = opendir($upload_path);
            while ($file = readdir($dir)) {
                if ($file != '.' && $file != '..') {
                    $download_link = "<a href=\"".$this->href('files.xml',$this->GetPageTag(),'action=download&file='.urlencode($file))."\">".$file."</a>";
                    if ($file == $uploaded['name'])
                        print "<em>{$download_link}</em>\n";
                    else
                        print $download_link;
                    print '<br>';
                }
            }  
            closedir($dir);
        }
        else {
            print "There are no files attached to this page.";
        }
}
?>
There are 6 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki