PHP image uploader from AS3


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //CODE
  2. import com.adobe.images.JPGEncoder;
  3. import flash.display.BitmapData;
  4. import flash.net.URLRequest;
  5. import flash.net.URLRequestHeader;
  6. import flash.net.URLRequestMethod;
  7. import flash.net.navigateToURL;
  8.  
  9. var myBitmapData:BitmapData = new BitmapData(100, 100, false, 0xFFFFFF);
  10. var jpgEncoder:JPGEncoder = new JPGEncoder(85);
  11. var jpgStream:ByteArray = jpgEncoder.encode(myBitmapData);
  12. var fileName:String='Name';
  13. jpgStream.writeMultiByte("_s_"+fileName,"us-ascii");
  14. var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
  15. var request:URLRequest = new URLRequest("myJpgSaver.php");
  16. request.requestHeaders.push(header);
  17. request.method = URLRequestMethod.POST;
  18. request.data = jpgStream;
  19. navigateToURL(request, "_blank");
  20. myBitmapData.dispose();
  21.  
  22. //myJpgSaver.php
  23. <?PHP
  24. if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
  25. {
  26. $parts=explode("_s_", $GLOBALS["HTTP_RAW_POST_DATA"]);
  27. $name=$parts[1];
  28. $fp = fopen( $name.".jpg", 'wb' );
  29. fwrite( $fp, $parts[0] );
  30. fclose( $fp );
  31. }
  32. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.