Actionscript 3 photobooth upload photo with PHP

  • MaxSoon
  • Born
  • Born
  • MaxSoon
  • Posts: 2

Post 3+ Months Ago

Morning everyone, in this few days I search for a lot references online and tried to make my first photobooth program with actionscript and PHP, finally I had done the actionscript part, but when I tried to upload my photo which took from actionscript to server via php, the problem had come. I follow and modify from the references and tutorials I found online, but the php part never work, so the last choice for me is look for professional help here, and below is my source code, any professional please tell me where's the problem is, thanks!

------------------------------------------------------------------------------------------------
ACTIONSCRIPT 3 SIDE:
------------------------------------------------------------------------------------------------
ACTIONSCRIPT Code: [ Select ]
stop();
 
 
//START CAMERA FUNCTION
 
 
import com.adobe.images.JPGEncoder;
 
 
var cam:Camera = Camera.getCamera();
 
 
cam.setMode(1890,940,15);
 
 
var video:Video = new Video(1900,940);
 
 
video.attachCamera(cam);
 
 
video.x = 20;
 
 
video.y = 20;
 
 
addChild(video);
 
 
import flash.display.Bitmap;
 
 
import flash.display.BitmapData;
 
 
 
 
var bitmapData:BitmapData = new BitmapData(video.width,video.height);
 
 
 
 
 
var imgBD:BitmapData;
var imgBitmap:Bitmap;
 
 
 
 
 
//Frame choosing
 
 
import flash.events.Event;
import flash.events.MouseEvent;
 
 
var addGreen1:Green1 = new Green1();
var addRed2:Red2 = new Red2();
var addYellow3:Yellow3 = new Yellow3();
var addBlue4:Blue4 = new Blue4();
var addOrange5:Orange5 = new Orange5();
 
 
btn_cframe.buttonMode=true;
btn1.buttonMode=true;
btn2.buttonMode=true;
btn3.buttonMode=true;
btn4.buttonMode=true;
btn5.buttonMode=true;
 
 
btn1.addEventListener(MouseEvent.CLICK, btnone);
 
 
function btnone(event:MouseEvent):void {
addGreen1.x= 0
addGreen1.y= 0
addChild(addGreen1);
addChild(addRed2);
addChild(addYellow3);
addChild(addBlue4);
addChild(addOrange5);
removeChild(addRed2);
removeChild(addYellow3);
removeChild(addBlue4);
removeChild(addOrange5);
}
 
 
btn2.addEventListener(MouseEvent.CLICK, btntwo);
 
 
function btntwo(event:MouseEvent):void {
addRed2.x= 0
addRed2.y= 0
addChild(addGreen1);
addChild(addRed2);
addChild(addYellow3);
addChild(addBlue4);
addChild(addOrange5);
removeChild(addGreen1);
removeChild(addYellow3);
removeChild(addBlue4);
removeChild(addOrange5);
}
 
 
btn3.addEventListener(MouseEvent.CLICK, btnthree);
 
 
function btnthree(event:MouseEvent):void {
addYellow3.x= 0
addYellow3.y= 0
addChild(addGreen1);
addChild(addRed2);
addChild(addYellow3);
addChild(addBlue4);
addChild(addOrange5);
removeChild(addGreen1);
removeChild(addRed2);
removeChild(addBlue4);
removeChild(addOrange5);
}
 
 
btn4.addEventListener(MouseEvent.CLICK, btnfour);
 
 
function btnfour(event:MouseEvent):void {
addBlue4.x= 0
addBlue4.y= 0
addChild(addGreen1);
addChild(addRed2);
addChild(addYellow3);
addChild(addBlue4);
addChild(addOrange5);
removeChild(addGreen1);
removeChild(addRed2);
removeChild(addYellow3);
removeChild(addOrange5);
}
 
 
btn5.addEventListener(MouseEvent.CLICK, btnfive);
 
 
function btnfive(event:MouseEvent):void {
addOrange5.x= 0
addOrange5.y= 0
addChild(addGreen1);
addChild(addRed2);
addChild(addYellow3);
addChild(addBlue4);
addChild(addOrange5);
removeChild(addGreen1);
removeChild(addRed2);
removeChild(addYellow3);
removeChild(addBlue4);
}
 
 
//button for user confirm the frame
 
btn_cframe.addEventListener(MouseEvent.CLICK, btn_cf)
 
 
function btn_cf(event:MouseEvent):void {
     btn_cframe.gotoAndStop(2);
     btn1.visible = false;
     btn2.visible = false;
     btn3.visible = false;
     btn4.visible = false;
     btn5.visible = false;
     shotBtn.visible=true;
     removeBtn.visible=true;
     sendBtn.visible=true;
     shotBtn.addEventListener(MouseEvent.CLICK, startCountdown);
     }
 
 
 
 
 
//shot or remove button
 
 
shotBtn.visible=false;
removeBtn.visible=false;
sendBtn.visible=false;
 
 
shotBtn.buttonMode=true;
removeBtn.buttonMode=true;
sendBtn.buttonMode=true;
 
 
var timer1:Timer = new Timer(6000);
 
 
timer1.addEventListener(TimerEvent.TIMER, countdowntimer);
 
 
 
 
var addcd_number:Cd_number = new Cd_number();
 
 
 
 
shotBtn.addEventListener(MouseEvent.CLICK, startCountdown);
 
 
function startCountdown(event:MouseEvent) {
 
     //trigger countdown graphic
     addcd_number.x= 788;
     addcd_number.y= 355;
     addcd_number.gotoAndPlay(2);
     addChild(addcd_number);
 
 
 
 
 
   
     shotBtn.removeEventListener(MouseEvent.CLICK, startCountdown);
 
 
      timer1.start();
}
 
function countdowntimer(e:Event){
 
     timer1.stop();
 
     removeBtn.addEventListener(MouseEvent.CLICK, removeSnapshot);
     sendBtn.addEventListener(MouseEvent.CLICK, uploadImage);
     removeChild(addcd_number);
 
     bitmapData.draw(video);
    imgBD = new BitmapData(1920,994);
    imgBD.draw(stage);
   
    imgBitmap = new Bitmap(imgBD);
    addChild(imgBitmap);
}
 
function removeSnapshot(event:MouseEvent):void {
    removeChild(imgBitmap);
    shotBtn.addEventListener(MouseEvent.CLICK, startCountdown);
     removeBtn.removeEventListener(MouseEvent.CLICK, removeSnapshot);
     sendBtn.removeEventListener(MouseEvent.CLICK, uploadImage);
}
 
 
 
 
 
 
// for connect the php side
 
 
function uploadImage(e:MouseEvent):void {
 
 
  var myEncoder:JPGEncoder = new JPGEncoder(100);
 
 
  var byteArray:ByteArray = myEncoder.encode(bitmapData);
 
 
 
 
 
  var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
 
 
 
 
 
  var saveJPG:URLRequest = new URLRequest("post.php?photosNo=" + input_txt.text);
 
 
  saveJPG.requestHeaders.push(header);
 
 
  saveJPG.method = URLRequestMethod.POST;
 
 
  saveJPG.data = byteArray;
 
 
 
 
 
  var urlLoader:URLLoader = new URLLoader();
 
 
  urlLoader.load(saveJPG);
 
  navigateToURL(new URLRequest("FORUM_NOT_ALLOW_ME_TOPOST_LINK"),"_self");
 
 
}
  1. stop();
  2.  
  3.  
  4. //START CAMERA FUNCTION
  5.  
  6.  
  7. import com.adobe.images.JPGEncoder;
  8.  
  9.  
  10. var cam:Camera = Camera.getCamera();
  11.  
  12.  
  13. cam.setMode(1890,940,15);
  14.  
  15.  
  16. var video:Video = new Video(1900,940);
  17.  
  18.  
  19. video.attachCamera(cam);
  20.  
  21.  
  22. video.x = 20;
  23.  
  24.  
  25. video.y = 20;
  26.  
  27.  
  28. addChild(video);
  29.  
  30.  
  31. import flash.display.Bitmap;
  32.  
  33.  
  34. import flash.display.BitmapData;
  35.  
  36.  
  37.  
  38.  
  39. var bitmapData:BitmapData = new BitmapData(video.width,video.height);
  40.  
  41.  
  42.  
  43.  
  44.  
  45. var imgBD:BitmapData;
  46. var imgBitmap:Bitmap;
  47.  
  48.  
  49.  
  50.  
  51.  
  52. //Frame choosing
  53.  
  54.  
  55. import flash.events.Event;
  56. import flash.events.MouseEvent;
  57.  
  58.  
  59. var addGreen1:Green1 = new Green1();
  60. var addRed2:Red2 = new Red2();
  61. var addYellow3:Yellow3 = new Yellow3();
  62. var addBlue4:Blue4 = new Blue4();
  63. var addOrange5:Orange5 = new Orange5();
  64.  
  65.  
  66. btn_cframe.buttonMode=true;
  67. btn1.buttonMode=true;
  68. btn2.buttonMode=true;
  69. btn3.buttonMode=true;
  70. btn4.buttonMode=true;
  71. btn5.buttonMode=true;
  72.  
  73.  
  74. btn1.addEventListener(MouseEvent.CLICK, btnone);
  75.  
  76.  
  77. function btnone(event:MouseEvent):void {
  78. addGreen1.x= 0
  79. addGreen1.y= 0
  80. addChild(addGreen1);
  81. addChild(addRed2);
  82. addChild(addYellow3);
  83. addChild(addBlue4);
  84. addChild(addOrange5);
  85. removeChild(addRed2);
  86. removeChild(addYellow3);
  87. removeChild(addBlue4);
  88. removeChild(addOrange5);
  89. }
  90.  
  91.  
  92. btn2.addEventListener(MouseEvent.CLICK, btntwo);
  93.  
  94.  
  95. function btntwo(event:MouseEvent):void {
  96. addRed2.x= 0
  97. addRed2.y= 0
  98. addChild(addGreen1);
  99. addChild(addRed2);
  100. addChild(addYellow3);
  101. addChild(addBlue4);
  102. addChild(addOrange5);
  103. removeChild(addGreen1);
  104. removeChild(addYellow3);
  105. removeChild(addBlue4);
  106. removeChild(addOrange5);
  107. }
  108.  
  109.  
  110. btn3.addEventListener(MouseEvent.CLICK, btnthree);
  111.  
  112.  
  113. function btnthree(event:MouseEvent):void {
  114. addYellow3.x= 0
  115. addYellow3.y= 0
  116. addChild(addGreen1);
  117. addChild(addRed2);
  118. addChild(addYellow3);
  119. addChild(addBlue4);
  120. addChild(addOrange5);
  121. removeChild(addGreen1);
  122. removeChild(addRed2);
  123. removeChild(addBlue4);
  124. removeChild(addOrange5);
  125. }
  126.  
  127.  
  128. btn4.addEventListener(MouseEvent.CLICK, btnfour);
  129.  
  130.  
  131. function btnfour(event:MouseEvent):void {
  132. addBlue4.x= 0
  133. addBlue4.y= 0
  134. addChild(addGreen1);
  135. addChild(addRed2);
  136. addChild(addYellow3);
  137. addChild(addBlue4);
  138. addChild(addOrange5);
  139. removeChild(addGreen1);
  140. removeChild(addRed2);
  141. removeChild(addYellow3);
  142. removeChild(addOrange5);
  143. }
  144.  
  145.  
  146. btn5.addEventListener(MouseEvent.CLICK, btnfive);
  147.  
  148.  
  149. function btnfive(event:MouseEvent):void {
  150. addOrange5.x= 0
  151. addOrange5.y= 0
  152. addChild(addGreen1);
  153. addChild(addRed2);
  154. addChild(addYellow3);
  155. addChild(addBlue4);
  156. addChild(addOrange5);
  157. removeChild(addGreen1);
  158. removeChild(addRed2);
  159. removeChild(addYellow3);
  160. removeChild(addBlue4);
  161. }
  162.  
  163.  
  164. //button for user confirm the frame
  165.  
  166. btn_cframe.addEventListener(MouseEvent.CLICK, btn_cf)
  167.  
  168.  
  169. function btn_cf(event:MouseEvent):void {
  170.      btn_cframe.gotoAndStop(2);
  171.      btn1.visible = false;
  172.      btn2.visible = false;
  173.      btn3.visible = false;
  174.      btn4.visible = false;
  175.      btn5.visible = false;
  176.      shotBtn.visible=true;
  177.      removeBtn.visible=true;
  178.      sendBtn.visible=true;
  179.      shotBtn.addEventListener(MouseEvent.CLICK, startCountdown);
  180.      }
  181.  
  182.  
  183.  
  184.  
  185.  
  186. //shot or remove button
  187.  
  188.  
  189. shotBtn.visible=false;
  190. removeBtn.visible=false;
  191. sendBtn.visible=false;
  192.  
  193.  
  194. shotBtn.buttonMode=true;
  195. removeBtn.buttonMode=true;
  196. sendBtn.buttonMode=true;
  197.  
  198.  
  199. var timer1:Timer = new Timer(6000);
  200.  
  201.  
  202. timer1.addEventListener(TimerEvent.TIMER, countdowntimer);
  203.  
  204.  
  205.  
  206.  
  207. var addcd_number:Cd_number = new Cd_number();
  208.  
  209.  
  210.  
  211.  
  212. shotBtn.addEventListener(MouseEvent.CLICK, startCountdown);
  213.  
  214.  
  215. function startCountdown(event:MouseEvent) {
  216.  
  217.      //trigger countdown graphic
  218.      addcd_number.x= 788;
  219.      addcd_number.y= 355;
  220.      addcd_number.gotoAndPlay(2);
  221.      addChild(addcd_number);
  222.  
  223.  
  224.  
  225.  
  226.  
  227.    
  228.      shotBtn.removeEventListener(MouseEvent.CLICK, startCountdown);
  229.  
  230.  
  231.       timer1.start();
  232. }
  233.  
  234. function countdowntimer(e:Event){
  235.  
  236.      timer1.stop();
  237.  
  238.      removeBtn.addEventListener(MouseEvent.CLICK, removeSnapshot);
  239.      sendBtn.addEventListener(MouseEvent.CLICK, uploadImage);
  240.      removeChild(addcd_number);
  241.  
  242.      bitmapData.draw(video);
  243.     imgBD = new BitmapData(1920,994);
  244.     imgBD.draw(stage);
  245.    
  246.     imgBitmap = new Bitmap(imgBD);
  247.     addChild(imgBitmap);
  248. }
  249.  
  250. function removeSnapshot(event:MouseEvent):void {
  251.     removeChild(imgBitmap);
  252.     shotBtn.addEventListener(MouseEvent.CLICK, startCountdown);
  253.      removeBtn.removeEventListener(MouseEvent.CLICK, removeSnapshot);
  254.      sendBtn.removeEventListener(MouseEvent.CLICK, uploadImage);
  255. }
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262. // for connect the php side
  263.  
  264.  
  265. function uploadImage(e:MouseEvent):void {
  266.  
  267.  
  268.   var myEncoder:JPGEncoder = new JPGEncoder(100);
  269.  
  270.  
  271.   var byteArray:ByteArray = myEncoder.encode(bitmapData);
  272.  
  273.  
  274.  
  275.  
  276.  
  277.   var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
  278.  
  279.  
  280.  
  281.  
  282.  
  283.   var saveJPG:URLRequest = new URLRequest("post.php?photosNo=" + input_txt.text);
  284.  
  285.  
  286.   saveJPG.requestHeaders.push(header);
  287.  
  288.  
  289.   saveJPG.method = URLRequestMethod.POST;
  290.  
  291.  
  292.   saveJPG.data = byteArray;
  293.  
  294.  
  295.  
  296.  
  297.  
  298.   var urlLoader:URLLoader = new URLLoader();
  299.  
  300.  
  301.   urlLoader.load(saveJPG);
  302.  
  303.   navigateToURL(new URLRequest("FORUM_NOT_ALLOW_ME_TOPOST_LINK"),"_self");
  304.  
  305.  
  306. }


------------------------------------------------------------------------------------------------
PHP SIDE:
------------------------------------------------------------------------------------------------

PHP Code: [ Select ]
<?php
 
 
if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){
 
 
  $jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
 
 
  $photosNo = $_GET["photosNo"];
 
 
  $filename = "images1/". mktime(). ".jpg";    
 
 
  if ($photosNo != 1 && $photosNo != 2 && $photosNo != 3 && $photosNo != 4 && $photosNo != 5) {
 
 
    $photosNo = "watermark";
 
 
  }
 
 
  $overlaying = "images1/" . $photosNo .".png";    
 
 
  $icon = imagecreatefrompng($overlaying);    
 
 
  file_put_contents($filename, $jpg);    
 
 
  $src_img = imagecreatefromjpeg($filename);  
 
 
  imagecopy ($src_img,$icon,0,0,0,0,30,30);    
 
 
  imagejpeg($src_img, $filename);    
 
 
 imagedestroy($icon);    
 
 
 } else{
 
 
   echo "Encoded JPEG information not received.";
 
 
 }  
 
 
$date = date("Ymd");  
 
 
$sql = "INSERT INTO webcam_booth (picurl,date) VALUES('$filename','$date')";  
 
 
  if(!mysql_query($sql, $con)) {
 
 
     die("ERROR!" . mysql_error());
 
 
   } else {
 
 
     header("Location:index.php");
 
 
   }
 
 
 ?>
  1. <?php
  2.  
  3.  
  4. if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){
  5.  
  6.  
  7.   $jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
  8.  
  9.  
  10.   $photosNo = $_GET["photosNo"];
  11.  
  12.  
  13.   $filename = "images1/". mktime(). ".jpg";    
  14.  
  15.  
  16.   if ($photosNo != 1 && $photosNo != 2 && $photosNo != 3 && $photosNo != 4 && $photosNo != 5) {
  17.  
  18.  
  19.     $photosNo = "watermark";
  20.  
  21.  
  22.   }
  23.  
  24.  
  25.   $overlaying = "images1/" . $photosNo .".png";    
  26.  
  27.  
  28.   $icon = imagecreatefrompng($overlaying);    
  29.  
  30.  
  31.   file_put_contents($filename, $jpg);    
  32.  
  33.  
  34.   $src_img = imagecreatefromjpeg($filename);  
  35.  
  36.  
  37.   imagecopy ($src_img,$icon,0,0,0,0,30,30);    
  38.  
  39.  
  40.   imagejpeg($src_img, $filename);    
  41.  
  42.  
  43.  imagedestroy($icon);    
  44.  
  45.  
  46.  } else{
  47.  
  48.  
  49.    echo "Encoded JPEG information not received.";
  50.  
  51.  
  52.  }  
  53.  
  54.  
  55. $date = date("Ymd");  
  56.  
  57.  
  58. $sql = "INSERT INTO webcam_booth (picurl,date) VALUES('$filename','$date')";  
  59.  
  60.  
  61.   if(!mysql_query($sql, $con)) {
  62.  
  63.  
  64.      die("ERROR!" . mysql_error());
  65.  
  66.  
  67.    } else {
  68.  
  69.  
  70.      header("Location:index.php");
  71.  
  72.  
  73.    }
  74.  
  75.  
  76.  ?>





Thanks for your time !
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 475

Post 3+ Months Ago

So this is something I haven't done yet but I'll try to help if I can I did do a bit of searching I found something that might help. It is not 100% transferable to your code.

UNTESTED
ACTIONSCRIPT Code: [ Select ]
 
function countdowntimer(e:Event){
 
    timer1.stop();
 
    removeBtn.addEventListener(MouseEvent.CLICK, removeSnapshot);
    sendBtn.addEventListener(MouseEvent.CLICK, uploadImage);
    removeChild(addcd_number);
 
    bitmapData.draw(video);
    imgBD = new BitmapData(1920,994);
    imgBD.draw(stage);
 
    // Based on my search you can try wrapping your capture in an image
    var myImage:Image = new Image();
    myImage.load( new Bitmap(imgBD) );
    myImage.content.width = 1920;
    myImage.content.height = 994;
 
    var imgBitmap:BitmapData = new BitmapData(1920,994, true, 0xffffffff );
    finished.draw(myImage);
    myImage = null;
 
    addChild(imgBitmap);
 
}
 
 
 
  1.  
  2. function countdowntimer(e:Event){
  3.  
  4.     timer1.stop();
  5.  
  6.     removeBtn.addEventListener(MouseEvent.CLICK, removeSnapshot);
  7.     sendBtn.addEventListener(MouseEvent.CLICK, uploadImage);
  8.     removeChild(addcd_number);
  9.  
  10.     bitmapData.draw(video);
  11.     imgBD = new BitmapData(1920,994);
  12.     imgBD.draw(stage);
  13.  
  14.     // Based on my search you can try wrapping your capture in an image
  15.     var myImage:Image = new Image();
  16.     myImage.load( new Bitmap(imgBD) );
  17.     myImage.content.width = 1920;
  18.     myImage.content.height = 994;
  19.  
  20.     var imgBitmap:BitmapData = new BitmapData(1920,994, true, 0xffffffff );
  21.     finished.draw(myImage);
  22.     myImage = null;
  23.  
  24.     addChild(imgBitmap);
  25.  
  26. }
  27.  
  28.  
  29.  


Again I don't know if this would work or not. Also when posting code there are code brackets you can use. in this case the following could be used

[actionscript]
// Your Actionscript Code here
[/actionscript]

[php]
// Your PHP Code here
[/php]
  • MaxSoon
  • Born
  • Born
  • MaxSoon
  • Posts: 2

Post 3+ Months Ago

Hi ScottG,

Thanks for your reply!

Actually for the actionscript image capture and everything are ok, the only problem is the connection between actionscript and PHP, I no sure why after I send the "post request" to php but php never generate/convert images to the folder in server.

I had put the whole things on online server and tested, but it still never worked, this is my first time to deal with PHP, so if any chance you know about PHP, please help me look at the PHP code and help me debug the error.

And the format of [actionscript][/actionscript][php][/php] noted, i will follow this format when next time I post anything. :)

Thanks again!
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 475

Post 3+ Months Ago

I do know php and the reason I suggested the as change is it seems like the as is not sending or sending the wrong info to php. Unfortunately debugging php that flash is contacting is a pain in the butt, Doable in many ways

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 14 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.