Photo capturing application using Flash and PHP

In this tutorial am going to explain how to create a webcam photo capturing application using Flash and PHP. This application works on flash platform. Flash will capture the photo and send to PHP to save it in web directory. I will also explain you the action script used to develop this application.

Online photo capturing application using flash and PHP

Photo capturing application using Flash and PHP

Basically it will create a video and get a bitmap image from it. The JPGE encoder will make it as a jpg image and send it to PHP. PHP will get image from flash using $GLOBALS[“HTTP_RAW_POST_DATA”] and save it in a directory.
You can view demo and download the example file below:

Download FileDemo

Below is the Action Script of flash for this application.

import flash.display.Bitmap;
import flash.display.BitmapData;
import com.adobe.images.JPGEncoder;

//Sound for the "Capture" button click
var snd:Sound = new camerasound(); 

//Set the maximum amount of bandwidth that the current outgoing video feed can use
//Should be in bytes per second.
var bandwidth:int = 0; 

// This value is 0-100 with 1 being the lowest quality. 
var quality:int = 100;

//Run Camera
var cam:Camera = Camera.getCamera();
cam.setQuality(bandwidth, quality);

//Now setMode(videoWidth, videoHeight, video fps, favor area)
var video:Video = new Video();
video.x = 20;
video.y = 20;

//Image Data
var bitmapData:BitmapData = new BitmapData(video.width,video.height);

var bitmap:Bitmap = new Bitmap(bitmapData);

//Set height and width for image
bitmap.x = 360;
bitmap.y = 20;

capture_mc.buttonMode = true;

//OnClick image captur

function captureImage(e:MouseEvent):void {;
	save_mc.buttonMode = true;
	save_mc.addEventListener(MouseEvent.CLICK, onSaveJPG);
	save_mc.alpha = 1;

save_mc.alpha = .5;

function onSaveJPG(e:Event):void{
	var myEncoder:JPGEncoder = new JPGEncoder(100);
	var byteArray:ByteArray = myEncoder.encode(bitmapData);
	var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
	//PHP fle to save the image
	var saveJPG:URLRequest = new URLRequest("save.php");
	saveJPG.method = URLRequestMethod.POST; = byteArray;
	var urlLoader:URLLoader = new URLLoader();
	urlLoader.addEventListener(Event.COMPLETE, sendComplete);
	function sendComplete(event:Event):void{
		warn.visible = true;
		warn.addEventListener(MouseEvent.MOUSE_DOWN, warnDown);
		warn.buttonMode = true;


Now flash captured image will send to save.php. Below is the php script to save this image in a directory.

//Now get the image form flash through HTTP_RAW_POST_DATA
	$img = $_GET["img"];
	//image Directory
	$filename = "images/webinfopedia_". mktime(). ".jpg";
	file_put_contents($filename, $jpg);
} else{
	//show error if image is not recived 
	echo "Encoded JPEG information not received.";

Hope that this will help you..

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>