dpjr86761 2011-06-16 09:54
浏览 43
已采纳

使用PHP从闪存到电子邮件图像和文本

I'm having a bit of trouble combining two things, sending text variables from flash and an image from flash. Here's what I do to email the image:

private function emailImage(imageToSend:MovieClip):void {
            trace("Sending Email");
            var data1:BitmapData = new BitmapData(imageToSend.width, imageToSend.height); 
            data1.draw(imageToSend);

            var en:JPGEncoder = new JPGEncoder(80);
            var bArray:ByteArray=   en.encode(data1);

            var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");

            var request:URLRequest = new URLRequest();
            request.requestHeaders.push(header);
            request.url = "http://192.168.1.117/mail.php";
            request.method = URLRequestMethod.POST;
            request.data = bArray;

            var loader:URLLoader = new URLLoader();
            loader.dataFormat = URLLoaderDataFormat.BINARY;
            loader.addEventListener(Event.COMPLETE, MailCompleteHandler);
            try
            {
                loader.load(request);
            }
            catch(error:Error)
            {
                trace("Unable to load URL");
            }
        }

And to email text variable I do this:

private function sendDataDB(Path:String) {
            var urlRequest:URLRequest = new URLRequest(Path);
            var loader:URLLoader = new URLLoader;
            urlRequest.method = URLRequestMethod.POST;
            var vars:URLVariables = new URLVariables;
            vars.cardID = cardID;
            vars.userName = userName;
            urlRequest.data = vars;
            loader.dataFormat = URLLoaderDataFormat.TEXT;
            loader.addEventListener(Event.COMPLETE,userDataStored);
            loader.load(urlRequest);
        }

But how do I do both, I want to send some text that would change for each user to be used as the body of the text and the email address but also send the picture to attach.

Thanks

EDIT: Would it work to append data to the end of the URL:

request.url = "http://192.168.1.117/mail.php";

Not sure how to go about this, the correct format for the URL or how to read it in on the PHP side.

  • 写回答

1条回答 默认 最新

  • dsl36367 2011-06-16 12:06
    关注

    Yes, the solution will be to send the variables as GET, along with the image as POST. Add the variables to the end of the URL, for example "http://192.168.1.117/mail.php?cardID=" + cardID + "&userName=" + userName.

    In your PHP file, you have a global $_GET variable, which will hold the variables passed via URL.

    $cardID = $_GET["cardID"];
    $userName = $_GET["userName"];
    

    If you need more detail, you can read this post: Sending byteArray and variables to server-side script at the same time.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)