You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.5 KiB
62 lines
2.5 KiB
<?php
|
|
// Asset upload. type=eve_logo, id=<module id>: logo of the Embed Video Encoder.
|
|
// The picture is stored as an RGBA PNG in data/assets/images/<md5>.png (the path la_mojo
|
|
// loads, relative to its working folder) and module_eve.logo_md5 is updated.
|
|
require_once('../ajax_asm.php');
|
|
if( $CUser->Data['id'] > 1 ){
|
|
$Data = array();
|
|
$Data['success'] = false;
|
|
$Data['msg'] = 'Wrong Parameters';
|
|
$TYPE = isset( $_POST['type'] ) ? strval( $_POST['type'] ) : '';
|
|
$MID = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
|
|
if( $TYPE == 'eve_logo' && $MID > 0 ){
|
|
$RR = $DATABASE->Query( "SELECT * FROM `modules` WHERE `id`={$MID} AND `type`=8", false );
|
|
if( !count( $RR ) ){
|
|
$Data['msg'] = 'Module Does Not Exists!';
|
|
} else if( !isset( $_FILES['file'] ) || $_FILES['file']['error'] != UPLOAD_ERR_OK || !is_uploaded_file( $_FILES['file']['tmp_name'] ) ){
|
|
$Data['msg'] = 'File upload failed!';
|
|
} else if( $_FILES['file']['size'] > 4 * 1024 * 1024 ){
|
|
$Data['msg'] = 'The picture is too big (max 4 MB)!';
|
|
} else if( !function_exists( 'imagecreatefromstring' ) ){
|
|
$Data['msg'] = 'PHP GD extension is missing!';
|
|
} else {
|
|
$IMG = @imagecreatefromstring( file_get_contents( $_FILES['file']['tmp_name'] ) );
|
|
if( $IMG === false ){
|
|
$Data['msg'] = 'Unsupported picture format!';
|
|
} else {
|
|
// normalise to a true colour picture with alpha channel (la_mojo uses alpha as mask)
|
|
$W = imagesx( $IMG );
|
|
$H = imagesy( $IMG );
|
|
$OUT = imagecreatetruecolor( $W, $H );
|
|
imagealphablending( $OUT, false );
|
|
imagesavealpha( $OUT, true );
|
|
imagefill( $OUT, 0, 0, imagecolorallocatealpha( $OUT, 0, 0, 0, 127 ) );
|
|
imagecopy( $OUT, $IMG, 0, 0, 0, 0, $W, $H );
|
|
imagedestroy( $IMG );
|
|
ob_start();
|
|
imagepng( $OUT );
|
|
$PNG = ob_get_clean();
|
|
imagedestroy( $OUT );
|
|
$MD5 = md5( $PNG );
|
|
$DIR = __DIR__.'/data/assets/images';
|
|
if( !is_dir( $DIR ) ) @mkdir( $DIR, 0775, true );
|
|
if( @file_put_contents( $DIR.'/'.$MD5.'.png', $PNG ) === false ){
|
|
$Data['msg'] = 'Unable to store the picture!';
|
|
} else {
|
|
$AUX = intval( $RR[0]['aux_id'] );
|
|
$DATABASE->DBLink->exec( "UPDATE `module_eve` SET `logo_md5`='{$MD5}' WHERE `id`={$AUX}" );
|
|
$Data['success'] = true;
|
|
$Data['msg'] = '';
|
|
$Data['md5'] = $MD5;
|
|
$Data['url'] = '/lib/controller/data/assets/images/'.$MD5.'.png';
|
|
$Data['width'] = $W;
|
|
$Data['height'] = $H;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
echo json_encode( $Data );
|
|
exit();
|
|
};
|
|
header( 'location: /');
|
|
?>
|