$base_path = dirname($_SERVER['SCRIPT_FILENAME']) . '/files/';
$base_url = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['PHP_SELF']) . '/files';
session_start();
header('Content-Type: text/html; charset=utf-8');
//var_dump($base_path); echo "
";
if (!@$_SESSION['perm']) {
header("Location: /",true,303);
exit();
}
if (strpos(@$_REQUEST['path'],'.')!==false)
$_REQUEST['path'] = '';
$_REQUEST['path'] = trim(@$_REQUEST['path']);
$_REQUEST['path'] = preg_replace("|^/|","",$_REQUEST['path']);
$_REQUEST['path'] = preg_replace('/\s/',"",$_REQUEST['path']);
$_REQUEST['file'] = preg_replace('|\s|',"",@$_REQUEST['file']);
$_REQUEST['file'] = preg_replace('|/|',"",$_REQUEST['file']);
//создание подкаталога
if (@$_REQUEST['createsubdir']==2) {
$_REQUEST['subdir'] = preg_replace("/[^a-z0-9_\\-]/","",strtolower(@$_REQUEST['subdir']));
mkdir($base_path.'/'.$_REQUEST['path'].'/'.$_REQUEST['subdir']);
mkdir($base_path.'/'.$_REQUEST['path'].'/'.$_REQUEST['subdir'].'/.thumb');
mkdir($base_path.'/'.$_REQUEST['path'].'/'.$_REQUEST['subdir'].'/.desc');
header("Location: {$_SERVER['SCRIPT_NAME']}?path={$_REQUEST['path']}",true,303);
exit();
}
//загрузка файла
if (@$_REQUEST['loadfile']==2) {
$uploaded_file = @$_FILES['filetoload'];
if (!is_uploaded_file($uploaded_file['tmp_name']))
die('загруженный файл не найден!');
$type = $uploaded_file['type'];
$pp = pathinfo($uploaded_file['name']);
$ext = strtolower(trim($pp['extension']));
$time = time();
$filename = "{$base_path}/{$_REQUEST['path']}/$time.$ext";
for ($i=0; file_exists($filename) && $i<10; $i) {
$time = time().$i.rand(0,1000);
$filename = "{$base_path}/{$_REQUEST['path']}/$time.$ext";
}
$preview = "{$base_path}/{$_REQUEST['path']}/.thumb/$time.$ext";
$descname = "{$base_path}/{$_REQUEST['path']}/.desc/$time.$ext.txt";
if (!move_uploaded_file($uploaded_file['tmp_name'],$filename))
die('ошибка при перемещении загруженного файла!');
//создание превью
createpreview($filename,$preview,$type);
//запись описания
file_put_contents($descname,$_REQUEST['desc']);
header("Location: {$_SERVER['SCRIPT_NAME']}?path={$_REQUEST['path']}",true,303);
exit();
}
//изменение файла
if (@$_REQUEST['changefile']==2) {
$uploaded_file = @$_FILES['filetoload'];
if (!is_uploaded_file($uploaded_file['tmp_name']))
die('загруженный файл не найден!');
$type = $uploaded_file['type'];
$filename = "{$base_path}/{$_REQUEST['path']}/{$_REQUEST['file']}";
$preview = "{$base_path}/{$_REQUEST['path']}/.thumb/{$_REQUEST['file']}";
$descname = "{$base_path}/{$_REQUEST['path']}/.desc/{$_REQUEST['file']}.txt";
if (!move_uploaded_file($uploaded_file['tmp_name'],$filename))
die('ошибка при перемещении загруженного файла!');
//создание превью
createpreview($filename,$preview,$type);
//запись описания
file_put_contents($descname,$_REQUEST['desc']);
header("Location: {$_SERVER['SCRIPT_NAME']}?path={$_REQUEST['path']}",true,303);
exit();
}
//изменить описание
if (@$_REQUEST['changedesc']==2) {
file_put_contents("$base_path/{$_REQUEST['path']}/.desc/{$_REQUEST['file']}.txt",$_REQUEST['desc']);
header("Location: {$_SERVER['SCRIPT_NAME']}?path={$_REQUEST['path']}",true,303);
exit();
}
//удаление файла
if (@$_REQUEST['delete']==2) {
$filename = "{$base_path}/{$_REQUEST['path']}/{$_REQUEST['file']}";
$preview = "{$base_path}/{$_REQUEST['path']}/.thumb/{$_REQUEST['file']}";
$descname = "{$base_path}/{$_REQUEST['path']}/.desc/{$_REQUEST['file']}.txt";
$deldirname = "{$base_path}/{$_REQUEST['path']}/.deleted";
@mkdir($deldirname);
rename($filename,"{$deldirname}/{$_REQUEST['file']}");
// @mkdir("{$deldirname}/.thumb");
// rename($preview,"{$deldirname}/.thumb/{$_REQUEST['file']}");
// @mkdir("{$deldirname}/.desc");
// rename($preview,"{$deldirname}/.desc/{$_REQUEST['file']}");
unlink($preview);
unlink($descname);
header("Location: {$_SERVER['SCRIPT_NAME']}?path={$_REQUEST['path']}",true,303);
exit();
}
//создание превью
function createpreview($filename,$previewname,$type) {
switch ($type) {
case 'image/gif':
$image = imagecreatefromgif($filename);
break;
case 'image/jpeg':
case 'image/pjpeg':
$image = imagecreatefromjpeg($filename);
break;
case 'image/png':
case 'image/x-png':
$image = imagecreatefrompng($filename);
break;
default:
return;
}
$width = 300; //максимальные размеры, в которые вписывается превью
$height = 200;
list($width_orig,$height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width_orig>$width) {
$height = $width/$ratio_orig;
} else if ($height_orig>$height) {
$width = $height*$ratio_orig;
} else {
$width = $width_orig;
$height = $height_orig;
}
$preview = imagecreatetruecolor($width, $height);
imagecopyresampled($preview,$image,0,0,0,0,$width,$height,$width_orig,$height_orig);
imagejpeg($preview,$previewname,100);
}
?>
show_tree($base_path,$_REQUEST['path'],0); ?> | //создать подкаталог if (@$_REQUEST['createsubdir']==1): ?> //загрузить файл elseif (@$_REQUEST['loadfile']==1): ?> //изменить файл elseif (@$_REQUEST['changefile']==1): @$desc = file_get_contents("$base_path/{$_REQUEST['path']}/.desc/{$_REQUEST['file']}.txt"); $desc = htmlspecialchars($desc,ENT_COMPAT | ENT_HTML401); ?> //изменить описание elseif (@$_REQUEST['changedesc']==1): @$desc = file_get_contents("$base_path/{$_REQUEST['path']}/.desc/{$_REQUEST['file']}.txt"); $desc = htmlspecialchars($desc,ENT_COMPAT | ENT_HTML401); ?> //удалить файл elseif (@$_REQUEST['delete']==1): @$desc = file_get_contents("$base_path/{$_REQUEST['path']}/.desc/{$_REQUEST['file']}.txt"); $desc = htmlspecialchars($desc,ENT_COMPAT | ENT_HTML401); ?> else: //показать содержимое каталога show_dir($base_path."/".$_REQUEST['path']); endif; ?> |