Exporting a mc as a Jpeg

Hi,
I’ve got the following code to create a jpeg from a MC. This all works fine, plus the php which saves it to the desktop.

The issue is when I go to open in. On the Mac and PC, neither will preview the image. However, on the Mac I can open the file no problem in Photoshop. Has anyone come across this issue?

The error message from Preview is: It may be damaged or use a file format that Preview doesn’t recognize.

function createJPG(mc:MovieClip, n:Number, fileName:String)
{
var jpgSource:BitmapData = new BitmapData (mc.width, mc.height);

            jpgSource.draw(mc);
            var jpgEncoder:JPGEncoder = new JPGEncoder(n);
            
            var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
            var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
            
            //Make sure to use the correct path to jpg_encoder_download.php
            
            var jpgURLRequest:URLRequest = new URLRequest ("download.php?name=" + fileName + ".jpg");
            jpgURLRequest.requestHeaders.push(header);
            jpgURLRequest.method = URLRequestMethod.POST;
            jpgURLRequest.data = jpgStream;
            
            var loader:URLLoader = new URLLoader();
            
            navigateToURL(jpgURLRequest, "_blank");
            
        }

PHP --------------------

<?php

if ( isset ( $GLOBALS[“HTTP_RAW_POST_DATA”] )) {

// get bytearray

$im = $GLOBALS[“HTTP_RAW_POST_DATA”];

// add headers for download dialog-box

header(‘Content-Type: image/jpeg’);

header(“Content-Disposition: attachment; filename=”.$_GET[‘name’]);

echo $im;

} else echo ‘An error occured.’;

?>