Files Handler
See also:
Documentation: FilesHandlerInfo.This is another a complete refactoring of the FilesManagementHandler I proposed previously. The new overview can be found at FilesManagementSolution
Dependancy
None.The code
to be saved as files.php in the handlers/page directory.- <div class="page">
 - <?php
 - function mkdir_r ($dir) {
 - }
 - }
 - 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();
 - // upload action
 - $uploaded = $_FILES['file'];
 - if ($_REQUEST['action'] == 'upload' AND $uploaded['size'] > 0)
 - // form
 - $result = "<form action=\"".$this->href()."/files\" method=\"post\" enctype=\"multipart/form-data\">\n";
 - if (!$this->config["rewrite_mode"]) $result .= "<input type=\"hidden\" name=\"wakka\" value=\"".$this->MiniHref()."/files\">\n";
 - echo $result;
 - // only if the user can write
 - if ($this->HasAccess('write'))
 - {
 - ?>
 - <input type="hidden" name="action" value="upload"><input type="file" name="file"><input type="submit" value="+">
 - <?php
 - }
 - echo "<a href=\"".$this->Href()."\">Back to the page</a>";
 - echo $this->FormClose();
 - // uploaded files
 - if ($file != '.' && $file != '..') {
 - // only if the user can write
 - if ($this->HasAccess('write'))
 - {
 - $delete_link = "<a href=\"".$this->href('files.xml',$this->GetPageTag(),'action=delete&file='.urlencode($file))."\">x</a>";
 - }
 - else
 - {
 - $delete_link = "-";
 - }
 - $download_link = "<a href=\"".$this->href('files.xml',$this->GetPageTag(),'action=download&file='.urlencode($file))."\">".$file."</a>";
 - print "[ {$delete_link} ] ";
 - if ($file == $uploaded['name'])
 - print "<em>{$download_link}</em>\n";
 - else
 - print $download_link;
 - print '<br>';
 - }
 - }
 - }
 - ?>
 - </div>
 
To Do
More comments in the code - comments standardization...CategoryDevelopmentHandlers