Save a .jpg or .png from flash

I’ve been working on a little flash app and I need to add the functionality of saving out a jpeg. For example, If I had a flash drawing program, how would I save out the picture I drew?

I’m sure I will need a PHP script to work alongside to create the image file.

Can anyone point me in the right direction?