В качестве исходника был взят:
http://www.wakkawiki.com/FilesAction
Там же есть небольшое обсуждение этого экшена.
Предназначен для:
Синтаксис:
Контроль доступа
actions/files.php
<?php
if (! $this->HasAccess('read', 'Actions/Files')) return;
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,0777));
}
}
$old_umask = umask(0);
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))."\">".htmlspecialchars($text)."</a>";
}
elseif (
$this->page) {
// upload path
if ($this->config['upload_path'] == '') $this->config['upload_path'] = 'files';
$upload_path = $this->config['upload_path'].'/'.$this->GetPageTag();
$HasAccessWrite = $this->HasAccess('write') && $this->HasAccess('write','Actions/Files');
if ($HasAccessWrite &&
($this->method <> 'print.xml') &&
($this->method <> 'edit')) {
if (!
is_dir($upload_path)) mkdir_r($upload_path);
// upload action
$uploaded = $_FILES['file'];
if ($_REQUEST['action'] == 'upload') {
$upload_max_size = (int)$this->config['upload_max_size'];
if ($upload_max_size > 0 && $uploaded['size'] > $upload_max_size*1024)
print "<b>File [{$uploaded['name']}] too long.</b><br>Max file size is {$upload_max_size}Kb<br>";
elseif ($uploaded['size'] > 0)
copy ($uploaded['tmp_name'], $upload_path.'/'.$uploaded['name']);
else
print "<b>File [{$uploaded['name']}] too long or empty.</b>";
}
// 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;
?>
<input type="hidden" name="action" value="upload"> <input type="file" name="file"> <input type="submit" value=" + ">
<?php
echo $this->FormClose();
}
if (
$HasAccessWrite || $show == '1') {
// uploaded files
$dir = opendir($upload_path);
while ($file = readdir($dir)) {
if ($file != '.' && $file != '..' && !is_dir($upload_path.'/'.$file)) {
$file_len = (int)(filesize($upload_path.'/'.$file)/1024 + 0.5);
$delete_link = "<a href=\"".$this->href('files.xml', $this->GetPageTag(), 'action=delete&file='.urlencode($file))."\">x</a>";
$download_link = "<a href=\"".$this->href('files.xml', $this->GetPageTag(), 'action=download&file='.urlencode($file))."\">".$file." ( {$file_len}K )</a>";
if ($HasAccessWrite) print "[ {$delete_link} ] ";
if ($file == $uploaded['name'])
print "<em>{$download_link}</em>\n";
else
print $download_link;
print '<br>';
}
}
closedir($dir);
}
}
umask($old_umask);
?>
Исправления:
YuriMakarov /23.07.2003 13:37/ Права доступа при создании папок для хранения файлов заменены на 0777 и добавлен umask(0) для корректной установки прав доступа. В предыдущем варианте использовались права 0755. При этом поскольку папки создавались под аккаунтом