Posted By

lorenz82 on 11/15/10


Tagged

php data image post upload as3 raw


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

lorenz82
alptugan
onemanstudio
tspitzr
dx0ne
mamadashi
dubogii
Karzin


PHP image uploader from AS3


 / Published in: ActionScript 3
 

  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
Posted By: Karzin on October 16, 2012

You may need to replace

navigateToURL(request)

by

var urlLoader:URLLoader = new URLLoader(); urlLoader.load(request);

Posted By: Karzin on October 17, 2012

You may need to replace

navigateToURL(request)

by

var urlLoader:URLLoader = new URLLoader(); urlLoader.load(request);

You need to login to post a comment.