Wikka : FilesHandler

HomePage :: Categories :: Index :: Changes :: Comments :: Documentation :: Blog :: Login/Register

Files Handler


See also:
Documentation: FilesHandlerInfo.
This is the development page for the Files handler.


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.

  1. <div class="page">
  2. <?php
  3. if (! function_exists('mkdir_r')) {
  4. � � � � function mkdir_r ($dir) {
  5. � � � � � � � � if (strlen($dir) == 0) return 0;
  6. � � � � � � � � if (is_dir($dir)) return 1;
  7. � � � � � � � � elseif (dirname($dir) == $dir) return 1;
  8. � � � � � � � � return (mkdir_r(dirname($dir)) and mkdir($dir,0755));
  9. � � � � }
  10. }
  11. if ($download <> '') {
  12. � � � � // link to download a file
  13. � � � � if ($text == '') $text = $download;
  14. � � � � echo "<a href=\"".$this->href('files.xml',$this->GetPageTag(),'action=download&file='.urlencode($download))."\">".$text."</a>";
  15. } elseif ($this->page AND ($this->method <> 'print.xml') AND ($this->method <> 'edit')) {
  16. � � � � // upload path
  17. � � � � if ($this->config['upload_path'] == '') $this->config['upload_path'] = 'files';
  18. � � � � $upload_path = $this->config['upload_path'].'/'.$this->GetPageTag();
  19. � � � � if (! is_dir($upload_path)) mkdir_r($upload_path);
  20. � � � � // upload action
  21. � � � � $uploaded = $_FILES['file'];
  22. � � � � if ($_REQUEST['action'] == 'upload' AND $uploaded['size'] > 0)
  23. � � � � � � � � copy ($uploaded['tmp_name'], $upload_path.'/'.$uploaded['name']);
  24. � � � � // form
  25. � � � � $result = "<form action=\"".$this->href()."/files\" method=\"post\" enctype=\"multipart/form-data\">\n";
  26. � � � � if (!$this->config["rewrite_mode"]) $result .= "<input type=\"hidden\" name=\"wakka\" value=\"".$this->MiniHref()."/files\">\n";
  27. � � � � echo $result;
  28. � � � � // only if the user can write
  29. � � � � if ($this->HasAccess('write'))
  30. � � � � {
  31. � � � � � � ?>
  32. � � � � � � <input type="hidden" name="action" value="upload"><input type="file" name="file"><input type="submit" value="+">
  33. � � � � � � <?php
  34. � � � � }
  35. � � � � echo "<a href=\"".$this->Href()."\">Back to the page</a>";
  36. � � � � echo $this->FormClose();
  37. � � � � // uploaded files
  38. � � � � $dir = opendir($upload_path);
  39. � � � � while ($file = readdir($dir)) {
  40. � � � � � � � � if ($file != '.' && $file != '..') {
  41. � � � � � � � � � � � � // only if the user can write
  42. � � � � � � � � � � � � if ($this->HasAccess('write'))
  43. � � � � � � � � � � � � {
  44. � � � � � � � � � � � � � � $delete_link = "<a href=\"".$this->href('files.xml',$this->GetPageTag(),'action=delete&file='.urlencode($file))."\">x</a>";
  45. � � � � � � � � � � � � }
  46. � � � � � � � � � � � � else
  47. � � � � � � � � � � � � {
  48. � � � � � � � � � � � � � � $delete_link = "-";
  49. � � � � � � � � � � � � }
  50. � � � � � � � � � � � � $download_link = "<a href=\"".$this->href('files.xml',$this->GetPageTag(),'action=download&file='.urlencode($file))."\">".$file."</a>";
  51. � � � � � � � � � � � � print "[ {$delete_link} ] ";
  52. � � � � � � � � � � � � if ($file == $uploaded['name'])
  53. � � � � � � � � � � � � � � � � print "<em>{$download_link}</em>\n";
  54. � � � � � � � � � � � � else
  55. � � � � � � � � � � � � � � � � print $download_link;
  56. � � � � � � � � � � � � print '<br>';
  57. � � � � � � � � }
  58. � � � � }
  59. � � � � closedir($dir);
  60. }
  61. ?>
  62. </div>


To Do

More comments in the code - comments standardization...


CategoryDevelopmentHandlers
There are 4 comments on this page. [Display comments]
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.2417 seconds