When you say you store the image in a variable in JavaScript, I assume you are referring to the client's web browser. If this is true, then you haven't yet transmitted it to the server much less stored it anywhere.
Typically you would make a POST request with the image in the form data and the target URL being a PHP script on the server that would process the POST data.
You would want to use an AJAX request instead of a simple form with an action="" URL to avoid leaving the current webpage and landing on the PHP script (which probably doesn't render any HTML, it would just be a blank page).
Libraries like jQuery can make doing POST requests very easy. Here are some tutorials on uploading images to web servers with jQuery and PHP:
http://phppot.com/php/php-ajax-image-upload/
That tutorial assumes you still have the server-side PHP file from their previous tutorial:
http://phppot.com/php/working-on-file-upload-using-php/