в Бане
Сообщения: 5,478
Регистрация: 07.05.2009 Откуда: Green Street | -Цитата от koshan - $upload_dir = "/uploads";
$extensions = array(
'jpg'=> array('pic.png', 'PictureItem(this)'),
'gif'=> array('pic.png', 'PictureItem(this)'),
'png'=> array('pic.png', 'PictureItem(this)'),
'mp3'=> array('aud.png', 'AudioItem(this)'),
'doc'=> array('doc.png', ''),
'docx'=> array('doc.png', ''),
'txt'=> array('txt.png', ''),
'xls'=> array('xls.png', '') ,
'xlsx'=> array('xls.png', ''),
'zip'=> array('arc.png', ''),
'rar'=> array('arc.png', ''),
'7z'=> array('arc.png', ''),
'pdf'=> array('pdf.png', ''),
);
// Транспонирование из киррилицы в латиницу
function charTranslit($cyr_chars) {
$associate = array(
" "=>"_", "А"=>"a", "Б"=>"b", "В"=>"v", "Г"=>"g", "Д"=>"d", "Е"=>"e", "Ё"=>"e", "Ж"=>"j", "З"=>"z", "И"=>"i", "Й"=>"j", "К"=>"k", "Л"=>"l", "М"=>"m", "Н"=>"n", "О"=>"o", "П"=>"p", "Р"=>"r", "С"=>"s", "Т"=>"t", "У"=>"u", "Ф"=>"f", "Х"=>"x", "Ц"=>"c", "Ч"=>"ch", "Ш"=>"sh", "Щ"=>"sch", "Ъ"=>"", "Ы"=>"i", "Ь"=>"", "Э"=>"e", "Ю"=>"u", "Я"=>"ya", "а"=>"a", "б"=>"b", "в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ё"=>"e", "ж"=>"j", "з"=>"z", "и"=>"i", "й"=>"j", "к"=>"k", "л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", "р"=>"r", "с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", "х"=>"x", "ц"=>"c", "ч"=>"ch", "ш"=>"w", "щ"=>"sch", "ъ"=>"", "ы"=>"i", "ь"=>"", "э"=>"e", "ю"=>"u", "я"=>"ya"
);
$chars = strtr($cyr_chars, $associate);
return $chars;
}
// Максимальный размер файлов на сервере
function maxFileSize() {
$upload_max = ini_get('upload_max_filesize');
$post_max = ini_get('post_max_size');
$max_size = ($upload_max < $post_max) ? $upload_max : $post_max;
return $max_size;
}
function Upload_files() {
global $upload_dir;
global $extensions;
$files = listDir($upload_dir);
global $message;
if (strlen($_FILES['filename']['name']) <= 4) {
echo 'Файл не выбран.';
echo '<script>setInterval(\'history.back(-1)\',2500)</script>';
die();
}
$pinfo = pathinfo($_FILES['filename']['name']);
$ext = strtolower($pinfo['extension']);
$_FILES['filename']['name'] = preg_replace("/[\s\(\)]/", "_", $_FILES['filename']['name']);
$_FILES['filename']['name'] = preg_replace("/[^А-яA-z0-9-_.]/", "", $_FILES['filename']['name']);
if (!array_key_exists($ext, $extensions)) {
echo 'Расширение <b>'.$ext.'</b> недопустимо.';
echo '<script>setInterval(\'history.back(-1)\',2500)</script>';
die();
}
$_FILES['filename']['name'] = str_replace(" ", "_", $_FILES['filename']['name']);
$_FILES['filename']['name'] = charTranslit($_FILES['filename']['name']);
while (in_array($_FILES['filename']['name'], $files))
$_FILES['filename']['name'] = "copy.".$_FILES['filename']['name'];
if (copy($_FILES['filename']['tmp_name'], $upload_dir.$_FILES['filename']['name']))
$message = 'Файл <b>'.$_FILES['filename']['name'].'</b> успешно загружен.';
else
$message = 'Произошла ошибка в процессе загрузки.';
}
function Delete_files() {
global $upload_dir;
global $message;
if(unlink($upload_dir.$_GET['del']))
$message = 'Файл <b>'.$_GET['del'].'</b> был успешно удален.';
else
$message = 'Возникла ошибка при удалении файла <b>'.$_GET['del'].'</b>';
}
$message = "";
if(isset($_GET['del']) && !isset($_FILES['filename'])) { Delete_files(); }
if(isset($_FILES['filename'])) { Upload_files(); }
$files = listDir($upload_dir);
$uploads = "/uploads";
if (!isset($_GET['ext'])) $_GET['ext'] = "all";
while (list($ind, $file)=each($files)) {
$pinfo = pathinfo($file);
$ext = strtolower($pinfo['extension']);
$name = $pinfo['basename'];
if (array_key_exists($ext, $extensions)) {
if ($_GET['ext'] == $ext Or $_GET['ext'] == "all") {
$filelist[$name]['name'] = $name;
$filelist[$name]['image'] = $extensions[$ext][0];
$filelist[$name]['action'] = $extensions[$ext][1];
$filelist[$name]['path'] = $uploads.$name;
$filelist[$name]['title'] = $uploads.'+'.$name;
}
}
}
?>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css">
<script type="text/javascript" src="upload.js"></script>
</head>
<body>
<div style="height: 20px;"><?=$message; ?></div>
<div style="float: right; display: inline;">Максимальный размер файла: <?=maxFileSize(); ?> Kb.</div>
<div style="display: inline;">
<a href="?ext=jpg">TXT</a>
<a href="?ext=doc">DOC</a>
<a href="?ext=docx">DOCX</a> |
<a href="?ext=pdf">PDF</a>
<a href="?ext=xls">XLS</a>
<a href="?ext=xlsx">XLSX</a> |
<a href="?ext=jpg">JPG</a>
<a href="?ext=gif">GIF</a>
<a href="?ext=png">PNG</a> |
<a href="?ext=zip">ZIP</a>
<a href="?ext=rar">RAR</a>
<a href="?ext=7z">7Z</a> |
<a href="?ext=mp3">MP3</a> |
<a href="?ext=all">ВСЕ</a>
</div>
<div class="files">
<table border=0 width="100%" cellpadding=0 cellspacing=0>
<? if(isset($filelist)): ?>
<? foreach($filelist as $file): ?>
<tr>
<td><img src="<?=$dir_path['wysiwyg'].'img/'.$file['image']; ?>"><a href="<?=$upload_dir.$file['name']; ?>"><?=$file['name']; ?></a></td>
<td width=40><? if($file['action']): ?><a href="java script:void(0)" onClick="<?=$file['action']; ?>" title="<?=$file['title']; ?>">Вставить</a><? endif; ?></td>
<td width=40><a href="java script:void(0)" onClick="LinkItem(this)" title="<?=$file['title']; ?>">Ссылка</a></td>
<td width=40><a href="upload.php?del=<?=$file['name']; ?>">Удалить</a></td>
<tr>
<? endforeach; ?>
<? else: ?>
<tr>
<td>Файлов нет</td>
</tr>
<? endif; ?>
</table>
</div>
<div class="uploader">
<form enctype="multipart/form-data" method=post>
<input type="file" class=input_file name=filename>
<input type="submit" value=" " class=upload_button>
</form>
</div>
</body>
</html> Помогите разобраться где ошибка =) там где написана ошибка) |