- <?php
- /**********************************
- * @package: PerfCMS *
- * @year: 2012 *
- * @author: Artas *
- * @link: http://perfcms.pp.ua *
- **********************************/
- $locate = 'in_share';
- if(!isset($user) || !isset($_GET['cat_id'])) { header('Location:/'); }
- if($db->query("SELECT * FROM `share_c` WHERE `id` = '". $_GET['cat_id'] ."'")->rowCount() == 0) {
- header('Location:/share/');
- }
- if(isset($_POST['add']) && $_GET['act'] == 'add') {
- $file_dir = ROOT .'/files/share/';
- if ($_FILES['file']['tmp_name']) {
- if(!empty($_POST['name'])) {$file_name = mb_substr(escape($_POST['name']), 0, 55);} else { $err = 'Name is empty'; }
- if(!empty($_POST['about'])) {$file_text = mb_substr(escape($_POST['about']), 0, 5000);} else { $err = 'Text is empty'; }
- $patch = pathinfo($_FILES['file']['name']);
- if (!in_array($patch['extension'], explode(';', $system['files_types']))) { $err = 'File extention not allowed.<br />'; }
- $name_start = cyrlat($patch['filename']);
- $name_short = trim($name_start).time();
- $name_end = mb_convert_encoding($name_short, "UTF-8");
- $name = 'perfcms_'.$name_end.'.'. $patch['extension'];
- if (file_exists($file_dir . $name)) { $err = 'This file exists<br />'; }
-
- if(!isset($err)) {
- move_uploaded_file($_FILES['file']['tmp_name'], $file_dir . $name);
- if (empty($file_name)) $file_name = str_replace('.'. $patch['extension'], '', $patch['basename']);
- $db->query("INSERT INTO `share_files` SET `time` = '". time() ."', `name` = '". input($file_name) ."', `size` = '". $_FILES['file']['size'] ."', `path_name` = '". $name."', `ext` = '$patch[extension]', `path` = '$file_dir', `user_id` = '". $user['id'] ."', `text` = '". input($file_text) ."', `cat_id` = '". $_GET['cat_id'] ."', `moderate` = '0'");
- // print_r($db->errorInfo());
- header('Location:/share/file/'. $db->lastInsertId() .'/');
- } else { echo $err; }
- }
- }
- elseif(isset($_POST['import']) && $_GET['act'] == 'import') {
- $file_dir = ROOT .'/files/share/';
- if (!empty($_POST['file'])) {
- if(!empty($_POST['name'])) {
- $file_name = mb_substr(escape($_POST['name']), 0, 55);
- }
- else {
- $err = 'Name is empty';
- }
- if(!empty($_POST['about'])) {
- $file_text = mb_substr(escape($_POST['about']), 0, 5000);
- }
- else {
- $err = 'Text is empty';
- }
- $urlinfo = pathinfo(parse_url(input($_POST['file']),PHP_URL_PATH));
- $name = 'perfcms_'.cyrlat($urlinfo['filename']).time().'.'.$urlinfo['extension'];
- if (file_exists($file_dir . $name)) { $err = 'This file exists<br />'; }
- copy(input($_POST['file']), ROOT.'/files/share/'.$name);
- $filesize = filesize(ROOT.'/files/share/'.$name);
- if(!isset($err)) {
- if (empty($file_name)) $file_name = $name;
- $db->query("INSERT INTO `share_files` SET `time` = '". time() ."', `name` = '". input($file_name) ."', `size` = '". $filesize ."', `path_name` = '". $name."', `ext` = '$urlinfo[extension]', `path` = '$file_dir', `user_id` = '". $user['id'] ."', `text` = '". input($file_text) ."', `cat_id` = '". $_GET['cat_id'] ."', `moderate` = '0'");
- // print_r($db->errorInfo());
- header('Location:/share/file/'. $db->lastInsertId() .'/');
- } else { echo $err; }
- }
- }
- if(isset($_GET['type']) && $_GET['type'] == 'import') {
- $title = $lang->word('import');
- require_once(SYS.'/view/header.php');
- $tpl->div('title', $lang->word('import'));
- echo '<form action="/share/add_file/'. $_GET['cat_id'] .'/?act=import" method="post">
- <div class="menu">
- <b>'. $lang->word('name') .'</b>:<br/>
- <input type="text" name="name" /><br/>
- <b>'. $lang->word('import_adress') .'</b>:<br/>
- <input name="file" type="text" value="http://"/><br/>
- <b>'. $lang->word('about') .'</b>:<br/>
- <textarea name="about" rows="5" cols="26"></textarea><br/>
- <input name="import" type="submit" value="'. $lang->word('import') .'" /><br/>
- </div>
- </form>';
- $tpl->div('block', img('upload.png'). '<a href="/share/add_file/'. $_GET['cat_id'] .'/">'.$lang->word('upload').'</a><br/>'. NAV .'<a href="/share/">'. $lang->word('share') .'</a><br/>' . HICO .'<a href="/">'. $lang->word('home').'</a>');
- require_once(SYS.'/view/footer.php');
- exit;
- }
- $title = $lang->word('add_file');
- require_once(SYS.'/view/header.php');
- $tpl->div('title', $lang->word('add_file'));
- echo '<form action="/share/add_file/'. $_GET['cat_id'] .'/?act=add" method="post" enctype="multipart/form-data">
- <div class="menu">
- <b>'. $lang->word('name') .'</b>:<br/>
- <input type="text" name="name" /><br/>
- <b>'. $lang->word('choose_file') .'</b>:<br/>
- <input name="file" type="file" /><br/>
- <b>'. $lang->word('about') .'</b>:<br/>
- <textarea name="about" rows="5" cols="26"></textarea><br/>
- <input name="add" type="submit" value="'. $lang->word('upload') .'" /><br/>
- </div>
- </form>';
- $tpl->div('block', img('upload.png'). '<a href="/share/add_file/'. $_GET['cat_id'] .'/?type=import">'.$lang->word('import').'</a><br/>'. NAV .'<a href="/share/">'. $lang->word('share') .'</a><br/>' . HICO .'<a href="/">'. $lang->word('home').'</a>');
- require_once(SYS.'/view/footer.php');
- ?>