Revision history for FilesHandler
Revision [19309]
Last edited on 2008-01-28 00:14:45 by MasinAlDujaili [Modified links pointing to docs server]No Differences
Additions:
%%(php;1)
function mkdir_r ($dir) {
if (strlen($dir) == 0) return 0;
if (is_dir($dir)) return 1;
elseif (dirname($dir) == $dir) return 1;
return (mkdir_r(dirname($dir)) and mkdir($dir,0755));
// 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>";
// 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 = "<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;
if ($this->HasAccess('write'))
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>";
print "[ {$delete_link} ] ";
if ($file == $uploaded['name'])
print "<em>{$download_link}</em>\n";
print $download_link;
print '<br>';
}
closedir($dir);
function mkdir_r ($dir) {
if (strlen($dir) == 0) return 0;
if (is_dir($dir)) return 1;
elseif (dirname($dir) == $dir) return 1;
return (mkdir_r(dirname($dir)) and mkdir($dir,0755));
// 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>";
// 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 = "<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;
if ($this->HasAccess('write'))
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>";
print "[ {$delete_link} ] ";
if ($file == $uploaded['name'])
print "<em>{$download_link}</em>\n";
print $download_link;
print '<br>';
}
closedir($dir);
Deletions:
function mkdir_r ($dir) {
if (strlen($dir) == 0) return 0;
if (is_dir($dir)) return 1;
elseif (dirname($dir) == $dir) return 1;
return (mkdir_r(dirname($dir)) and mkdir($dir,0755));
}
// 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>";
// 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 = "<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;
if ($this->HasAccess('write'))
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>";
print "[ {$delete_link} ] ";
if ($file == $uploaded['name'])
print "<em>{$download_link}</em>\n";
else
print $download_link;
print '<br>';
}
}
closedir($dir);
Additions:
=====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)
<div class="page">
<?php
if (! function_exists('mkdir_r')) {
function mkdir_r ($dir) {
if (strlen($dir) == 0) return 0;
if (is_dir($dir)) return 1;
elseif (dirname($dir) == $dir) return 1;
return (mkdir_r(dirname($dir)) and mkdir($dir,0755));
}
}
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)) 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 = "<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
$dir = opendir($upload_path);
while ($file = readdir($dir)) {
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>';
}
}
closedir($dir);
}
?>
</div>
%%
===To Do===
More comments in the code - comments standardization...
----
CategoryDevelopmentHandlers
>>==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)
<div class="page">
<?php
if (! function_exists('mkdir_r')) {
function mkdir_r ($dir) {
if (strlen($dir) == 0) return 0;
if (is_dir($dir)) return 1;
elseif (dirname($dir) == $dir) return 1;
return (mkdir_r(dirname($dir)) and mkdir($dir,0755));
}
}
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)) 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 = "<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
$dir = opendir($upload_path);
while ($file = readdir($dir)) {
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>';
}
}
closedir($dir);
}
?>
</div>
%%
===To Do===
More comments in the code - comments standardization...
----
CategoryDevelopmentHandlers
Deletions:
>>==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)
<div class="page">
<?php
if (! function_exists('mkdir_r')) {
function mkdir_r ($dir) {
if (strlen($dir) == 0) return 0;
if (is_dir($dir)) return 1;
elseif (dirname($dir) == $dir) return 1;
return (mkdir_r(dirname($dir)) and mkdir($dir,0755));
}
}
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)) 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 = "<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
$dir = opendir($upload_path);
while ($file = readdir($dir)) {
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>';
}
}
closedir($dir);
}
?>
</div>
%%
===To Do===
More comments in the code - comments standardization...
----
CategoryDevelopment
Additions:
This is another a complete refactoring of the FilesManagementHandler I proposed previously. The new overview can be found at FilesManagementSolution
Deletions:
Additions:
This is another a complete refactoring of the FilesManagementSolution I proposed previously.
Deletions:
Additions:
//to be saved as files.php in the handlers/page directory.//
Additions:
=====Files Handler=====
Documentation: FilesHandlerInfo.>>This is the development page for the Files handler.::c::
This is another a complete refactoring of the FilesManagementHandler I proposed previously.
===Dependancy===
None.
===The code===
%%(php)
<div class="page">
<?php
if (! function_exists('mkdir_r')) {
function mkdir_r ($dir) {
if (strlen($dir) == 0) return 0;
if (is_dir($dir)) return 1;
elseif (dirname($dir) == $dir) return 1;
return (mkdir_r(dirname($dir)) and mkdir($dir,0755));
}
}
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)) 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 = "<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
$dir = opendir($upload_path);
while ($file = readdir($dir)) {
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>';
}
}
closedir($dir);
}
?>
</div>
%%
===To Do===
More comments in the code - comments standardization...
Documentation: FilesHandlerInfo.>>This is the development page for the Files handler.::c::
This is another a complete refactoring of the FilesManagementHandler I proposed previously.
===Dependancy===
None.
===The code===
%%(php)
<div class="page">
<?php
if (! function_exists('mkdir_r')) {
function mkdir_r ($dir) {
if (strlen($dir) == 0) return 0;
if (is_dir($dir)) return 1;
elseif (dirname($dir) == $dir) return 1;
return (mkdir_r(dirname($dir)) and mkdir($dir,0755));
}
}
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)) 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 = "<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
$dir = opendir($upload_path);
while ($file = readdir($dir)) {
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>';
}
}
closedir($dir);
}
?>
</div>
%%
===To Do===
More comments in the code - comments standardization...
Deletions:
Documentation: xxxxxHandlerInfo.>>This is the development page for the xxxxx handler.::c::
//This page is a **template**. It belongs to CategoryTemplate (which contains more handy templates). To create a handler development page, [[http://wikka.jsnx.com/HandlerTemplate/clone clone this page]] to a page called **xxxxxHandler** (where xxxxx is the (capitalized) name of the handler), replace all occurrences of 'xxxxx' with the name of the handler and replace this paragraph with the actual content.//