santyas
santyas

Reputation: 96

Flash doesnt recognize the file type to get 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

Upvotes: 0

Views: 179

Answers (1)

Nambew
Nambew

Reputation: 640

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.

Upvotes: 1

Related Questions