douhu2525 2014-03-20 14:38
浏览 44
已采纳

Flash无法识别文件类型以获取AS3 PHP

Im programming in as3 flash and php a button where you can download a file .zip file. This gets the path from a php (proxy), but it cant recognize the file type and also fails to run the COMPLETE event. The idea of ​​this is to hide where the zip file is located. I dont understand where the problem is. The as3 code:

package {
    imports...

    public class Main extends MovieClip{
        var download_button:MovieClip;
        var req:URLRequest;
        var file:FileReference;
        var proxy:String = "http://www.domain.com/audio/proxy.php?url=";
        var filename:String = "file.zip";
        var status:TextField = new TextField();

        public function Main() {
            download_btn.addEventListener(MouseEvent.CLICK, promptDownload);
            status.text = "Bienvenido";
            addChild(status);
        }

        private function promptDownload(e:MouseEvent):void {
            req = new URLRequest(proxy + filename);
            file = new FileReference();

            file.addEventListener(Event.COMPLETE, completeHandler);
            file.addEventListener(Event.CANCEL, cancelHandler);
            file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            file.download(req, "file.zip");
        }

        private function cancelHandler(event:Event):void {
            trace("User canceled the download");
            status.text = "Cancelado";
        }

        private function completeHandler(event:Event):void {
            trace("Download complete");
            status.text = "Completado";
        }

        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioError occurred");
            status.text = "Error";
        }
    }
}

and the php code:

$filename = "http://www.domain.com/audio/files" . $_GET['url'];

$archivo = "file.zip";
$len = filesize($filename);
$outname = $archivo;

header("Content-type: application/zip");

// Optional but the error is the same
//header("Expires: -1");
//header("Last-Modified: " . gmdate('D, d M Y H:i:s') . " GMT");
//header("Content-Transfer-Encoding: binary");
//header("Cache-Control: no-store, no-cache, must-revalidate");
//header("Cache-Control: post-check=0, pre-check=0");
//header("Pragma: no-cache");
//header("Content-Length:".$len);
//header("Content-Disposition: attachment; filename=".$outname);

readfile($filename);

thank you very much

  • 写回答

1条回答 默认 最新

  • doubei5114 2014-03-20 16:33
    关注

    The actionscript work perfectly on my localhost, I download the zip file. You should check the PHP, you don't need to use http url to read file on the same server.

    $filename = "http://www.domain.com/audio/files" . $_GET['url'];
    

    This line is really a security hole, a hacker can get all your file, you need to escape this variable and check if the filename is legit.

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

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1