66 lines
2.4 KiB
PHP
66 lines
2.4 KiB
PHP
<?php
|
|
|
|
ini_set('display_errors', 0);
|
|
|
|
//print_r($_POST);
|
|
switch(@$_POST['act']) {
|
|
/* 05.05.2021 Загрузка фотографий */
|
|
case 'foto_upload':
|
|
unset($_POST['act']);
|
|
// if ($_SESSION != 'a' || $_SESSION != 'e') header( 'Location: /403/' );
|
|
if ( $_FILES['file']['tmp_name'] ){
|
|
// print_r($_FILES);
|
|
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $_FILES['file']['name'] ) ){
|
|
/* 06.05.2021 вычисляем контрольную сумму чтобы дважды не загружать одно и то же */
|
|
unset($id);
|
|
$md5['md5'] = md5_file( $_FILES['file']['tmp_name'] );
|
|
/* ищем в базе - есть ли оно */
|
|
$id = $db -> get_val( 'upload', $md5, 'id' );
|
|
if ( $id )die( 'Уже есть такое' );
|
|
@mkdir( MYDIR . '/img/users', 0700 );
|
|
@mkdir( MYDIR . '/img/users/' . $_SESSION['user_id'], 0700 );
|
|
require_once MYDIR . '/api/php/genpass.php';
|
|
$img_name = generate_password( 20 );
|
|
$source = $_FILES['file']['tmp_name'];
|
|
$target_original = MYDIR . '/img/users/' . $_SESSION['user_id'] . '/' . $img_name . '.jpg';
|
|
copy( $source, $target_original );
|
|
unset( $a );
|
|
$a['rnd_name'] = $img_name;
|
|
$a['pages_id'] = $_SESSION['page_id'];
|
|
$a['original_name'] = $_FILES['file']['name'];
|
|
$a['type'] = 'img';
|
|
$a['user_id'] = $_SESSION['user_id'];
|
|
$a['md5'] = $md5['md5'];
|
|
$db -> add( 'upload', $a );
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 'update_settings':
|
|
unset($_POST['act']);
|
|
$db->update_settings($_POST);
|
|
break;
|
|
|
|
case 'upload_main_img':
|
|
|
|
//echo 'uploader';
|
|
$settings_mod = $db -> get_settings_json($_POST['mod']);
|
|
unset($_POST['act']);
|
|
$tmp_name = $db -> upload_img( $_FILES, 'pages', 'main_img');
|
|
$db -> resize_img($tmp_name, $settings_mod['w'], $settings_mod['h'], 80, false, 'pages');
|
|
$db -> resize_img($tmp_name, $settings_mod['p_w'], $settings_mod['p_h'], 80, true, 'pages');
|
|
unset($a);
|
|
$a['id']=$_POST['id'];
|
|
$json=$db->get_val('pages', $a, 'json');
|
|
$massiv=$db->from_j($db-> clear_json($json));
|
|
$massiv['main_img']=$tmp_name;
|
|
$json=$db->to_j($massiv);
|
|
$db->free_sql( "UPDATE `pages` SET `json` = '" . $json . "' WHERE `id` = " . $_POST['id'] );
|
|
echo $tmp_name;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
}
|
|
?>
|