[AS3]as3的php版上传图片并以Base64编码字符串提交代码示例
[AS3]as3的php版上传图片并以Base64编码字符串提交代码示例,as3的base64,base64加密,Base64编码
- package
- {
- import com.adobe.images.JPGEncoder;
- import com.adobe.images.PNGEncoder;
- import com.hurlant.util.Base64;
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.Loader;
- import flash.display.MovieClip;
- import flash.display.Shape;
- import flash.display.Sprite;
- import flash.events.Event;
- import fl.controls.Button;
- import flash.events.MouseEvent;
- import flash.filters.GlowFilter;
- import flash.net.*;
- import flash.filters.BitmapFilterQuality;
- import flash.utils.ByteArray;
- /**
- * ...
- * @author ZhangYi
- */
- publicclass Base64Test extends Sprite
- {
- private var _base:Shape;
- private var _btn:Button;
- private var _loader:Loader;
- public function Base64Test()
- {
- if (stage) init();
- else addEventListener(Event.ADDED_TO_STAGE, init);
- }
- private function init(e:Event = null):void
- {
- removeEventListener(Event.ADDED_TO_STAGE, init);
- // entry point
- inited();
- }
- private function inited():void {
- var mc:MovieClip = new MovieClip();
- mc.graphics.beginFill(0x000000, 0.2);
- mc.graphics.drawRect(0, 0, 320, 455);
- mc.x = 30;
- mc.y = 60;
- addChild(mc);
- _loader = new Loader();
- _loader.load(new URLRequest("../assets/1.png"));
- mc.addChild(_loader);
- _loader.addEventListener(MouseEvent.ROLL_OVER, addFilterHandler);
- _loader.addEventListener(MouseEvent.ROLL_OUT, removeFilterHandler);
- _btn = new Button();
- _btn.label = "截图";
- _btn.x = 30;
- _btn.y = 30;
- addChild(_btn);
- _btn.addEventListener(MouseEvent.CLICK, clickHandler);
- }
- private function clickHandler(evt:MouseEvent):void {
- addFilterHandler();
- var bitmapData:BitmapData = new BitmapData(_loader.width, _loader.height, true, 0);
- bitmapData.draw(_loader);
- var bytes:ByteArray = PNGEncoder.encode(bitmapData);
- var pngString:String = Base64.encodeByteArray(bytes);
- var variables:URLVariables = new URLVariables();
- variables.png = pngString;
- variables.name = "photo002";
- var req:URLRequest = new URLRequest("http://Cuplayer.com/test/uploadFile/upload_2.php");
- req.data = variables;
- req.method = URLRequestMethod.POST;
- var urlloader:URLLoader = new URLLoader();
- urlloader.dataFormat = URLLoaderDataFormat.VARIABLES;
- urlloader.addEventListener(Event.COMPLETE, completeHandler);
- urlloader.load(req);
- trace(pngString);
- }
- private function completeHandler(evt:Event):void {
- trace(evt.target.data);
- }
- private function addFilterHandler(evt:MouseEvent=null):void {
- var filtersArr:Array = new Array();
- filtersArr = _loader.filters;
- filtersArr.push(getBitmapFilter());
- _loader.filters = filtersArr;
- }
- private function removeFilterHandler(evt:MouseEvent):void {
- _loader.filters = null;
- }
- private function getBitmapFilter():GlowFilter {
- var color:Number = 0xFF0000;
- var alpha:Number = 1;
- var blurX:Number = 5;
- var blurY:Number = 5;
- var strength:Number = 4;
- var inner:Boolean = false;
- var knockout:Boolean = false;
- var quality:Number = BitmapFilterQuality.LOW;
- returnnew GlowFilter(color, alpha, blurX, blurY, strength, quality, inner, knockout);
- }
- }
- }
后台php代码:
- <?php
- function base64_to_png($inputfile, $outputfile ) {
- $imageData = $inputfile;
- $file = fopen( $outputfile, "w" );
- fwrite( $file, base64_decode( $imageData ) );
- fclose($file);
- }
- base64_to_png("".$_POST['png'], "image/". $_POST["name"] . ".png");
- print"info=ok!!";
- ?>
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...