开发者

Sending data from Flash to PHP using POST method

开发者 https://www.devze.com 2023-03-08 09:29 出处:网络
I have a developed a application that allows users to draw simple images on a canvas. The name of the movieclip(canvas) is canvas_mc.

I have a developed a application that allows users to draw simple images on a canvas. The name of the movieclip(canvas) is canvas_mc.

I need to save th开发者_运维问答is drawing on the server using php. I have to convert the movieclip (canvas_mc) into png and jpeg and save it. I have successfully save it on local drive using some classes available in

http://www.flashandmath.com/advanced/smoothdraw/index.html

How can I save it on server using PHP. I have been asked to use the post method. If possible give me the code also as I just moved into programming from design :-)


Not sure about how to convert your image into data and such, but here's a class I have lying around that you can use to transfer data to a PHP script (which can from there insert the data into a database).

package
{
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.net.URLVariables;
    import flash.net.URLRequestMethod;
    import flash.events.Event;

    /**
     * @author Marty Wallace
     * @version 1.00
     */
    public class PHPData extends Object
    {
        /**
         * Sends data to a PHP script
         * @param script A URL to the PHP script
         */
        public function send(script:String, vars:URLVariables):void
        {
            var req:URLRequest = new URLRequest(script);

            req.data = vars;
            req.method = URLRequestMethod.POST;

            var loader:URLLoader = new URLLoader();
            loader.load(req);

            // listeners
            loader.addEventListener(Event.COMPLETE, _complete);
        }

        /**
         * Called when a response has been received from a PHP script
         * @param e Event.COMPLETE
         */
        private function _complete(e:Event):void
        {
            var vars:URLVariables = new URLVariables(e.target.data);

            var i:String;
            for(i in vars)
            {
                trace(i + ": " + vars[i]);
            }

            e.target.removeEventListener(Event.COMPLETE, _complete);
        }
    }
}

Use:

var php:PHPData = new PHPData();
var vars:URLVariables = new URLVariables();

vars.imagedata = your_image_data;

php.send("your_php_script.php", vars);
0

精彩评论

暂无评论...
验证码 换一张
取 消