This is my scenario:
I have a web server running php
I have a client with a receipt printer
I have a HTML form that retrieves various data from the user and stores them in a database. Then I can access it as I want.
What I want to do is that when I click on a print button, the server sends a command to the printer to print the ticket.
I'm trying to do this with Mike32's escpos-php library but I can't do it.
Here is the php file I made
<?php
require 'vendor/autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
$data = "Hello world !";
$printerName = 'Custom';
$clientName = 'LAPTOP-J3MTKIN3';
$connector = new WindowsPrintConnector("\\\\$clientName\\$printerName");
try {
$printer = new Printer($connector);
$printer->text($data);
$printer->cut();
$printer->close();
} catch (Exception $e) {
echo "Erreur : " . $e->getMessage() . "\n";
}
?>
Here are the 2 errors I get:
Warning: preg_match(): Compilation failed: invalid range in character
class at offset 29 in
/var/www/html/vendor/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php
on line 126
and
Fatal error: Uncaught BadMethodCallException: Printer
'\LAPTOP-J3MTKIN3\Custom' is not a valid printer name. Use local port
(LPT1, COM1, etc) or smb://computer/printer notation. in
/var/www/html/vendor/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php:155
Stack trace: #0 /var/www/html/test_impression.php(22):
Mike42\Escpos\PrintConnectors\WindowsPrintConnector->__construct() #1
{main} thrown in
/var/www/html/vendor/mike42/escpos-php/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php
on line 155
Related
I have successfully installed ZeroMQ in WAMP, see the screenshot below.
However I am getting Error:
Fatal error: Uncaught Error: Class 'ZMQContext' not found in C:\wamp64\www\0MQ\zguide\examples\PHP\hwclient.php:9 Stack trace: #0 {main} thrown in C:\wamp64\www\0MQ\zguide\examples\PHP\hwclient.php on line 9
when I run a test script in a browser:
TEST SCRIPT:
<?php
/*
* Hello World client
* Connects REQ socket to tcp://localhost:5555
* Sends "Hello" to server, expects "World" back
* #author Ian Barber <ian(dot)barber(at)gmail(dot)com>
*/
$context = new ZMQContext();
// Socket to talk to server
echo "Connecting to hello world server...\n";
$requester = new ZMQSocket($context, ZMQ::SOCKET_REQ);
$requester->connect("tcp://localhost:5555");
for ($request_nbr = 0; $request_nbr != 10; $request_nbr++) {
printf ("Sending request %d...\n", $request_nbr);
$requester->send("Hello");
$reply = $requester->recv();
printf ("Received reply %d: [%s]\n", $request_nbr, $reply);
}
How may I deal with this?
I added this configuration line:
[ZMQ]
extension=php_zmq.dll
to php.ini located in:
c:\wamp64\bin\php\php7.1.9\php.ini
rather than in:
c:\wamp64\bin\apache\apache2.4.27\bin\php.ini
This solved the problem.
This is the first time I use parse.com php SDK and I try to execute the following code
<?php require '../autoload.php';
use Parse\ParseObject;
use Parse\ParseClient;
ParseClient::initialize( "Zsr...", "BzM..", "D..." );
$gameScore = new ParseObject("GameScore");
$gameScore->set("score", 1337);
$gameScore->set("playerName", "Sean Plott");
$gameScore->set("cheatMode", false);
try {
$gameScore->save();
echo 'New object created with objectId: ' . $gameScore->getObjectId();
} catch (ParseException $ex) {
// Execute any logic that should take place if the save fails.
// error is a ParseException object with an error code and message.
echo 'Failed to create new object, with error message: ' + $ex->getMessage();
}
?>
But I get that error
Fatal error: Uncaught exception 'Parse\ParseException' with message 'SSL certificate problem: unable to get local issuer certificate' in /opt/lampp/htdocs/parse/src/Parse/ParseClient.php:250 Stack trace: #0 /opt/lampp/htdocs/parse/src/Parse/ParseObject.php(925): Parse\ParseClient::_request('POST', '/1/classes/Game...', NULL, '{"score":1337,"...', false) #1 /opt/lampp/htdocs/parse/src/Parse/ParseObject.php(836): Parse\ParseObject::deepSave(Object(Parse\ParseObject), false) #2 /opt/lampp/htdocs/parse/src/hola.php(11): Parse\ParseObject->save() #3 {main} thrown in /opt/lampp/htdocs/parse/src/Parse/ParseClient.php on line 250
The code it's the tutorial code, iI haven't changed anything anyone knows what's the problem?
I am also getting same issue. Now I resolve using some other forums answer.
Open your ParseClient.php and find:
curl_init();
And after that add line add:
curl_setopt($rest, CURLOPT_SSL_VERIFYPEER, false);
It will work.
I am trying to ultimately run and display reports from a remote Jasper Server in a PHP application. What I am trying to do this with is the jrs-rest-php-client project on github.
The error:
Fatal error: Uncaught exception 'Jaspersoft\Exception\RESTRequestException' with message 'An unexpected HTTP status code was returned by the server' in C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Tool\RESTRequest.php:409
Stack trace:
#0 C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Tool\RESTRequest.php(479): Jaspersoft\Tool\RESTRequest->handleError(0, Array, false)
#1 C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Service\ReportService.php(40): Jaspersoft\Tool\RESTRequest->prepAndSend('https://jasper....', Array, 'GET', NULL, true)
#2 C:\xampp\htdocs\jrs\report.php(30): Jaspersoft\Service\ReportService->runReport('/Reports/Distri...', 'html')
#3 {main} thrown in C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Tool\RESTRequest.php on line 409
My PHP:
require_once __DIR__ . "/vendor/autoload.php";
use Jaspersoft\Client\Client;
$d = new Client(
"http://jasper.server.com/jasperserver-pro",
"username",
"password",
"organization"
);
$info = $d->serverInfo();
Any ideas?
Looking into the code of RESTRequest.php there are two cases in which this exception is thrown:
A JSON result set with an unknown error code is returned (unknown meaning different from 200 OK)
No JSON result set is returned at all
So I suspect the connection isn't working properly. To find out more, you should catch the exception in your code and evaluate it:
It could look something like this (I'm more familiar with Java):
try {
$d = new Client(
"http://jasper.server.com/jasperserver-pro",
"username",
"password",
"organization"
);
$info = $d->serverInfo();
} catch (RESTRequestException $e) {
echo 'RESTRequestException:';
echo 'Exception message: ', $e->getMessage(), "\n";
echo 'Set parameters: ', $e->parameters, "\n";
echo 'Expected status code:', $e->expectedStatusCodes, "\n";
echo 'Error code: ', $e->errorCode, "\n";
}
If there is still an error, you can check the following:
Can you reach the jasper server from the server where this code is deployed? Sometimes e.g. firewall settings can interfere.
Is the organization called exactly like defined in the properties of the organization in the server? (Open repository / right click on organization / properties / resource-id)
i'm trying to open MyComputer using COM class ... whould you help me with the name of MyComputer in COM class ??
For example , if you wanna open NotePad you do this :
<?php
$shell = new COM("WScript.Shell");
$shell->Run("notepad.exe");
$shell = null; ?>
Run("notepad.exe"); works for notepad , but when i use Run("mycomputer.exe"); i face error :
Fatal error: Uncaught exception 'com_exception' with message 'Source: UnknownDescription: Unknown' in E:\Localhost\root\test.php:3 Stack trace: #0 E:\Localhost\root\test.php(3): com->Run('computer.exe') #1 {main} thrown in E:\Localhost\root\test.php on line 3
i appreciate any help from you my dear friends <3
you can try :
<?php
$shell = new COM("WScript.Shell");
$shell->Run("explorer.exe ,");
$shell = null; ?>
when we add "," it open My computer.
Hi I keep geting the following error when I try to delete a number from my twilio subaccount using REST API in PHP
my code is;
$number = $twClient->account->incoming_phone_numbers->get($number_Sid);
$twClient->account->incoming_phone_numbers->delete($number->sid);
The error that I am getting is;
[22-Aug-2013 09:40:17 UTC] PHP Fatal error: Uncaught exception 'Services_Twilio_RestException' with message 'The requested resource was not found' in C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php- 732e6f6\Services\Twilio.php:226
Stack trace:
#0 C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php- 732e6f6\Services\Twilio.php(145): Services_Twilio->_processResponse(Array)
#1 C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php-732e6f6\Services\Twilio.php(179): Services_Twilio->_makeIdempotentRequest(Array, '/2010-04-01/Acc...', 1)
#2 C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php-732e6f6\Services\Twilio\ListResource.php(71): Services_Twilio->deleteData('/2010-04-01/Acc...', Array)
#3 C:\Program Files (x86)\Zend\Apache2\htdocs\testers\web2call\application\controllers\clientphonenos_controller.php(518): Services_Twilio_ListResource->delete('PN397fc000ce6f8...')
#4 [internal function]: ClientPhoneNos_controller->data_form('delete', '+14139926551_AC...')
#5 C:\Program Files (x86)\Zend\Apache2\htdocs\system\core\Cod in C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php-732e6f6\Services\Twilio.php on line 226
If you have already successfully deleted the phone number, Twilio will return a 404 Not Found to you, which the PHP library will interpret as a RestException. You can only delete the phone number one time :)
You can override exception by using this syntax:
try
{
// do something that can go wrong
}
catch (Exception $e)
{
throw new Exception( 'Something really gone wrong', 0, $e);
}
Here's another live sample for sending messages with an exception catcher:
<?PHP
require "Services/Twilio.php";
// Set our AccountSid and AuthToken from twilio.com/user/account
$AccountSid = "{ACCOUNTSID}";
$AuthToken = "{AUTHTOKEN}";
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
/* Your Twilio Number or Outgoing Caller ID */
$from = '2126404004';
$people = array("212-716-1130");
$body = "Enter your text message here";
$errorIds = array(); //user ids array which had broken phones
foreach ($people as $to) {
try
{
$client->account->sms_messages->create($from, $to, $body);
echo "Sent message to: $to \n <br>";
}
catch (Exception $e)
{ //on error push userId in to error array
$count++;
array_push($errorIds, $to);
}
}
print_r($errorIds);
?>
Without catching the exception, the script will die with an error like:
<br>PHP Fatal error: Uncaught exception 'Services_Twilio_RestException' with message 'The message From/To pair violates a blacklist rule.' in /var/www/vhosts/httpdocs/twilio/Services/Twilio.php:149