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

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.

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么