-2

Me php code run immediately mouseout event.

Me situation:

$("#canvas").mouseout(function() {
    isDrawing = false;

     var sourceCanvas = ctxPaint.getImageData(0, 0, cw, ch); 
     ctxPaint.clearRect(0, 0, cw, ch);
     ctxPaint.putImageData(sourceCanvas, 0, 0); 

     var data = canvasPaint.toDataURL('image/gif'); 
     var ajax = new XMLHttpRequest();
     ajax.open("POST", 'upload_data.php', false);
     ajax.setRequestHeader('Content-Type', 'application/upload');
     ajax.send(data);

     <?php
     m = new Image("png");
     $im->mergeImages("images/urlL", "png", "name", "png", "600", "500", "600", "300", "finish");
     ?>

});

Maybe somebody have idea?

user3778390
  • 375
  • 1
  • 6
  • 16
  • 1
    It is not possible... ;) – Zemistr Jul 04 '14 at 13:30
  • 1
    This code doesn't make any sense. The `m = ` line looks like Javascript, should not be in the `?>` tags. And whatever the output of the next next is...? Also, *PHP* does not *run* Javascript. A browser does. Check the source the browser sees. – Jared Farrish Jul 04 '14 at 13:30

3 Answers3

2

Php is executed only when the page is loaded. It's a server side language. JS is a client side language. If you want to execute php code in JS, the only way is to call a php page in ajax how will contain the php code you need to execute.

Yoann Augen
  • 1,966
  • 3
  • 21
  • 39
1

You can not execute PHP code in JavaScript, it does not make any sense.

Your Javascript is executed in browser, while PHP scipts are running on server side. You should implement your upload_data.php with image processing on server.

zavg
  • 10,351
  • 4
  • 44
  • 67
1

Your code is executed in browsers. Browsers are restricted for security reasons and do not execute external interpreters like PHP. JavaScript is a builtin of common browsers.

JavaScript can be executed as a server side script. There you can execute PHP interpreters. However, server side code can not be driven by client events such as mouseout. This is not what you want.

You have to send AJAX requests to a PHP site, run PHP on the server and submit the generated data in a format suitable to process in client side scripts, e.g. HTML, XML, JSON.

Pinke Helga
  • 6,378
  • 2
  • 22
  • 42