Файл: modules/albums/add_photo.php
Строк: 86
<?php
/**
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) 2013, Taras Chornyi, Sergiy Mazurenko, Ivan Kotliar
* @link http://perf-engine.net
* @package PerfEngine
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
$locate = 'in_photo_albums';
$al_id = (isset($_GET['id']) ? num($_GET['id']) : 0);
if($db->query("SELECT * FROM `albums` WHERE `id` = '$al_id'")->rowCount() == 0 || $db->query("SELECT user_id FROM `albums` WHERE `id` = '$al_id'")->fetchColumn() != User::Id())
{
redirect('/albums/');
}
if(!User::logged())
{
redirect('/');
}
$err = false;
if(isset($_GET['add']))
{
if($_FILES['file']['tmp_name'])
{
$desc = input($_POST['file_desc']);
$file_info = pathinfo($_FILES['file']['name']);
$file_info['extension'] = strtolower($file_info['extension']);
if (!in_array($file_info['extension'], explode(';', 'png;gif;jpg;jpeg')))
{
$err = 'File extension not allowed.<br />';
}
$name = cyrlat($file_info['filename']);
$serv_name = trim($name).'_'.rand(1000, 50000);
$servname = preg_replace('/[^а-яА-Яa-zA-Z0-9_-]/isU', '', $serv_name).'.'.$file_info['extension'];
if($err == false)
{
move_uploaded_file($_FILES['file']['tmp_name'], ROOT.'/files/albums/'.$al_id.'/'.$servname);
import_lib('jimage.class');
$mini = new jimage();
$mini->thumb(ROOT.'/files/albums/'.$al_id.'/'.$servname, ROOT.'/cache/albums/thumbs/'.$al_id.'/'.$serv_name.'.jpg', 150, 130);
$db->query("UPDATE `users` SET `balance` = '".(User::profile('balance')+1)."' WHERE `id` = '". User::Id() ."'");
$db->query("INSERT INTO `albums_photo` SET `description` = '$desc', `server_name` = '$al_id/$serv_name', `album_id` = '$al_id', `ext` = '".$file_info['extension']."', `user_id` = '".User::Id()."', `time` = '". time() ."'");
// print_r($db->errorInfo());
redirect('/albums/photo/'.$db->lastInsertId());
}
}
}
include_header(_t('add_photo'));
echo '<div class="title">'. _t('add_photo') .'</div>';
echo ($err != false ? '<div class="error">'. $err .'</div>' : false);
echo '<div class="menu">
<form action="/albums/add_photo/'.$al_id.'/?add" method="post" enctype="multipart/form-data">
<b>'. _t('dl_choose_file') .'</b>:<br/>
<input name="file" type="file" accept="image/*"/><br/>
'._t('desc_photo').':<br/>
<textarea name="file_desc" rows="5" cols="25"></textarea><br/>
<input type="submit" value="'. _t('add') .'" />
</form>
</div>';
echo '<div class="block">
'. NAV.' <a href="/albums/album/'.$al_id.'">'._t('back').'</a><br/>'
. NAV.' <a href="/albums">'. _t('photo_albums').'</a><br/>'
.HICO.' <a href="/">'._t('home').'</a>';
include_footer();
?>