Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // RawPrintServer INSTALL "EPSON LX-310 ESC/P" 2481
- if ( isset( $_REQUEST['q'] ) ){
- $socket = socket_create( AF_INET, SOCK_STREAM, 0 ) or die( "Error socket\r\n" );
- $result = socket_connect( $socket, "127.0.0.1", 2481 ) or die( "Error connecting\r\n" );
- $message = $_REQUEST['q'];
- socket_write( $socket, $message, strlen( $message ) ) or die( "Error sending\r\n" );
- socket_close( $socket );
- die( strlen( $_REQUEST['q'] ) );
- }
- ?>
- <textarea name=q readonly cols=152 rows=25 >{1B}{21}{01}{1B}M{0F}{1B}{C1}{0B}Hello, world!
- {0E}Double-width{14}
- </textarea>
- <button type=button name=button value=button >Print</button>
- <script>
- document.querySelector( '[name=button]' ).addEventListener( 'click', e=>{
- var http = new XMLHttpRequest();
- http.open( 'POST', 'raw-print-server.php', true );
- http.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
- http.onreadystatechange = function() {
- if ( http.readyState == 4 && http.status == 200 ) {
- console.log( http.response );
- alert( "Printed: " + http.response + " bytes" );
- }
- }
- var params = 'q=' + encodeURIComponent( document.querySelector('[name=q]').value
- .replace(/\{([0-9a-fA-F][0-9a-fA-F])\}/g, function(m,x){
- return String.fromCharCode(parseInt(x, 16));
- }) );
- http.send(params);
- }, false );
- </script>
Add Comment
Please, Sign In to add comment