PHP execution may be asyncronous?
<p>I made a little trial using JS upon canvas and images. The final part of it calls a page where at the beginning I try to write upon the server the final image. The process suppose that a previous file exists, not complete:</p>

<pre><code>&lt;?php
$filename = explode(".", $_POST["trans_file"]); // name of the image file
if (!unlink("transit/" . $_POST["trans_file"])) echo "File " . $_POST["trans_file"] . "not found!&lt;br /&gt;";       // remove the partial file
$filesave = $filename[0] . ".png";              // I will save a PNG file
$filejpg = $filename[0] . ".jpg";               // but I will transform it into JPG
$data = $_POST["base64img_data"];               // here I receive the base64 image by a previous process
$data = explode(";", $data);                    // I remove the first part of it
$data = explode(",", $data[1]);                 // $data[1] now contains the base64 image complete
$image=base64_decode(chunk_split($data[1]));    // $image is now a PNG file
$handle = fopen("transit/$filesave", "wb");     // Create a PNG file
fwrite($handle, $image);                        // write it
fclose($handle);                                // Close, and transform it into JPG
    png2jpg("transit/$filesave", "transit/$filejpg", 100);
    unlink("transit/$filesave");                // remove PNG image
</code></pre>

<p>I've put this at the beginning of the page, but the browser displays always the previous file, the one cancelled at the beginning, and being itself a JPG.
Strange enough (for me) this sequence is working perfectly upon one server, not working upon a different one!
I suppose it should be a case of asyncronous execution of PHP and JS inside the page.
How may I syncronize server and browser?
Thank you.</p>
