core/api/modules/set_img/ajax.php

32 lines
926 B
PHP
Raw Permalink Normal View History

2022-12-11 13:55:49 +05:00
<?php
switch( @$_POST['act'] ) {
case 'new_category':
serialize ( $_SESSION )
if ( $_FILES['file']['tmp_name'] ){
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $_FILES['file']['name'] ) ){
require_once MYDIR . '/api/php/genpass.php';
$img_name = generate_password( 10 );
$source = $_FILES['file']['tmp_name'];
$target = MYDIR . '/img/avatars/' . $img_name . '.jpg';
copy( $source, $target );
}
require_once MYDIR . '/api/php/img2.php';
rimg ( $target, 740, 556, $target, $zip=80, $c=0 );
echo $img_name;
//узнаем старую аватарку и удаляем
unset( $a );
$a['id'] = $_SESSION['user_id'];
$ava = $db -> get_val( 'users', $a, 'ava' );
unlink( MYDIR . '/img/avatars/' . $ava . '.jpg' );
unset( $a );
$a['ava'] = $img_name;
$db -> update( 'users', $_SESSION['user_id'], $a );
}
break;
default:
}