Create image from movieclip

Hi I want to be able to create an image from a movieclip or the whole scene and upload it on a ftp server and to a database.

I have one working solution for something close to this but it only lets me download the image

switch ($_POST[“format”])
case ‘jpg’:
header(‘Content-Type: image/jpeg’);

case 'png':
header('Content-Type: image/png');


if ($_POST[‘action’] == ‘prompt’)
header(“Content-Disposition: attachment; filename=”.$_POST[‘fileName’]);

echo base64_decode($_POST[“image”]);

how can I get this code to upload the image to the server and database instead?