=====Files Handler===== >>==See also:== Documentation: FilesHandlerInfo.>>This is the development page for the Files handler.::c:: 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.// %%(php;1)
'') { // link to download a file if ($text == '') $text = $download; echo "href('files.xml',$this->GetPageTag(),'action=download&file='.urlencode($download))."\">".$text.""; } 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)) mkdir_r($upload_path); // upload action $uploaded = $_FILES['file']; if ($_REQUEST['action'] == 'upload' AND $uploaded['size'] > 0) copy ($uploaded['tmp_name'], $upload_path.'/'.$uploaded['name']); // form $result = "
href()."/files\" method=\"post\" enctype=\"multipart/form-data\">\n"; if (!$this->config["rewrite_mode"]) $result .= "MiniHref()."/files\">\n"; echo $result; // only if the user can write if ($this->HasAccess('write')) { ?> Href()."\">Back to the page"; echo $this->FormClose(); // uploaded files $dir = opendir($upload_path); while ($file = readdir($dir)) { if ($file != '.' && $file != '..') { // only if the user can write if ($this->HasAccess('write')) { $delete_link = "href('files.xml',$this->GetPageTag(),'action=delete&file='.urlencode($file))."\">x"; } else { $delete_link = "-"; } $download_link = "href('files.xml',$this->GetPageTag(),'action=download&file='.urlencode($file))."\">".$file.""; print "[ {$delete_link} ] "; if ($file == $uploaded['name']) print "{$download_link}\n"; else print $download_link; print '
'; } } closedir($dir); } ?>
%% ===To Do=== More comments in the code - comments standardization... ---- CategoryDevelopmentHandlers