Web Interface For Lite Argus Control modules
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

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. // Asset upload. type=eve_logo, id=<module id>: logo of the Embed Video Encoder.
  3. // The picture is stored as an RGBA PNG in data/assets/images/<md5>.png (the path la_mojo
  4. // loads, relative to its working folder) and module_eve.logo_md5 is updated.
  5. require_once('../ajax_asm.php');
  6. if( $CUser->Data['id'] > 1 ){
  7. $Data = array();
  8. $Data['success'] = false;
  9. $Data['msg'] = 'Wrong Parameters';
  10. $TYPE = isset( $_POST['type'] ) ? strval( $_POST['type'] ) : '';
  11. $MID = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;
  12. if( $TYPE == 'eve_logo' && $MID > 0 ){
  13. $RR = $DATABASE->Query( "SELECT * FROM `modules` WHERE `id`={$MID} AND `type`=8", false );
  14. if( !count( $RR ) ){
  15. $Data['msg'] = 'Module Does Not Exists!';
  16. } else if( !isset( $_FILES['file'] ) || $_FILES['file']['error'] != UPLOAD_ERR_OK || !is_uploaded_file( $_FILES['file']['tmp_name'] ) ){
  17. $Data['msg'] = 'File upload failed!';
  18. } else if( $_FILES['file']['size'] > 4 * 1024 * 1024 ){
  19. $Data['msg'] = 'The picture is too big (max 4 MB)!';
  20. } else if( !function_exists( 'imagecreatefromstring' ) ){
  21. $Data['msg'] = 'PHP GD extension is missing!';
  22. } else {
  23. $IMG = @imagecreatefromstring( file_get_contents( $_FILES['file']['tmp_name'] ) );
  24. if( $IMG === false ){
  25. $Data['msg'] = 'Unsupported picture format!';
  26. } else {
  27. // normalise to a true colour picture with alpha channel (la_mojo uses alpha as mask)
  28. $W = imagesx( $IMG );
  29. $H = imagesy( $IMG );
  30. $OUT = imagecreatetruecolor( $W, $H );
  31. imagealphablending( $OUT, false );
  32. imagesavealpha( $OUT, true );
  33. imagefill( $OUT, 0, 0, imagecolorallocatealpha( $OUT, 0, 0, 0, 127 ) );
  34. imagecopy( $OUT, $IMG, 0, 0, 0, 0, $W, $H );
  35. imagedestroy( $IMG );
  36. ob_start();
  37. imagepng( $OUT );
  38. $PNG = ob_get_clean();
  39. imagedestroy( $OUT );
  40. $MD5 = md5( $PNG );
  41. $DIR = __DIR__.'/data/assets/images';
  42. if( !is_dir( $DIR ) ) @mkdir( $DIR, 0775, true );
  43. if( @file_put_contents( $DIR.'/'.$MD5.'.png', $PNG ) === false ){
  44. $Data['msg'] = 'Unable to store the picture!';
  45. } else {
  46. $AUX = intval( $RR[0]['aux_id'] );
  47. $DATABASE->DBLink->exec( "UPDATE `module_eve` SET `logo_md5`='{$MD5}' WHERE `id`={$AUX}" );
  48. $Data['success'] = true;
  49. $Data['msg'] = '';
  50. $Data['md5'] = $MD5;
  51. $Data['url'] = '/lib/controller/data/assets/images/'.$MD5.'.png';
  52. $Data['width'] = $W;
  53. $Data['height'] = $H;
  54. };
  55. };
  56. };
  57. };
  58. echo json_encode( $Data );
  59. exit();
  60. };
  61. header( 'location: /');
  62. ?>