0

这是我的第一个ActionScript 3应用程序。它应该将数据上传到特定位置,该位置应该是 www 根位置 - upload.php 所在的位置。

运行 ActionScript 应用程序后,我可以选择文件,我可以看到正在上传数据,但我找不到它

请你好心,帮我了解发生了什么,我怎样才能找到上传的数据?我检查了两个:临时文件位置和目标目的地。

这是动作脚本代码:

    package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;
    public class ch30ex2 extends Sprite {
        protected var fileRef:FileReference;
        protected var uploadButton:TestButton;
        protected var tf:TextField;
        protected const YOUR_UPLOAD_URL:String = "http://localhost/Saifa/www/upload.php";

        public function ch30ex2() {
            fileRef = new FileReference();
            fileRef.addEventListener(Event.SELECT, selectHandler);
            fileRef.addEventListener(Event.CANCEL, cancelHandler);
            fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            fileRef.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
            fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler);
            fileRef.addEventListener(Event.COMPLETE, completeHandler);

            var btn:TestButton;
            btn = new TestButton(100, 25, "Browse...");
            btn.addEventListener(MouseEvent.CLICK, function(event:Event):void {
                fileRef.browse();
            });
            btn.x = btn.y = 20;
            addChild(btn);

            uploadButton = btn = new TestButton(100, 25, "Upload");
            btn.addEventListener(MouseEvent.CLICK, function(event:Event):void {
                fileRef.upload(new URLRequest(YOUR_UPLOAD_URL));
            });
            btn.x = 20; btn.y = 55;
            addChild(btn);

            tf = new TextField();
            tf.defaultTextFormat = new TextFormat("_sans", 11, 0);
            tf.multiline = tf.wordWrap = true;
            tf.autoSize = TextFieldAutoSize.LEFT;
            tf.width = 300; tf.x = 130; tf.y = 58;
            addChild(tf);

            cancelHandler(null);
        }
        protected function selectHandler(event:Event):void {
            tf.text = fileRef.name;
            uploadButton.mouseEnabled = uploadButton.tabEnabled = true;
            uploadButton.alpha = 1;
        }
        protected function cancelHandler(event:Event):void {
            tf.text = "";
            uploadButton.mouseEnabled = uploadButton.tabEnabled = false;
            uploadButton.alpha = 0.3;
        }
        protected function progressHandler(event:ProgressEvent):void {
            tf.text = "Uploading " + 
                event.bytesLoaded + " / " + event.bytesTotal + "bytes ...";
        }
        protected function errorHandler(event:ErrorEvent):void {
            tf.text = event.text;
        }
        protected function completeHandler(event:Event):void {
            tf.text = "Upload complete!";
        }
    }
}
import flash.display.*;
import flash.text.*;
class TestButton extends Sprite {
    public var label:TextField;
    public function TestButton(w:Number, h:Number, labelText:String) {
        graphics.lineStyle(0.5, 0, 0, true);
        graphics.beginFill(0xa0a0a0);
        graphics.drawRoundRect(0, 0, w, h, 8);
        label = new TextField();
        addChild(label);
        label.defaultTextFormat = new TextFormat("_sans", 11, 0, true, false,
            false, null, null, "center");
        label.width = w;
        label.height = h;
        label.text = labelText;
        label.y = (h - label.textHeight)/2 - 2;
        buttonMode = true;
        mouseChildren = false;
    }
}

这是 PHP 代码,它应该复制临时上传的文件:

<?php
move_uploaded_file($_FILES[‘Filedata’][‘tmp_name’], ‘./‘.time().$_FILES[‘Filedata’][‘name’]);
?>

所有代码均来自ActionScript Bible book

我想请教以下内容:

  • 我的问题的可能根源是什么?
  • 看起来我的代码正确吗?它由 FlashBuilder 编译,没有问题
  • 如何确定问题的根源?
  • 如果您有一个运行 ActionScript + PHP 应用程序的示例,我会很高兴看到它。

当我花了几个小时尝试各种事情和组合时,我希望有人可能遇到过类似的问题。谢谢你。

4

1 回答 1

1
于 2012-09-18T22:16:52.333 回答