Browse and download files from server using Flash AS3 and PHP

Posted on 2010-01-03
Last Modified: 2013-11-11
How can I browse and download files from a server in flash using actionscript 3 and php?
Question by:Lunar76
    LVL 17

    Expert Comment

    In PHP you should write code to send files to visitor, like


    and in code inside write a code which reads file content and prints it out, like filecontent function

    In ActionScript 3 make an HTTP request to PHP and get it's output.


    Author Comment

    Thanks CSecurity, but can you show me some as3 and php code, that does this exactly?
    LVL 17

    Expert Comment

    It's the PHP part
    if (isset($_GET['filename'])) 
    $file= $_GET['filename'];
    if (file_exists($file))
               header("Pragma: public");
               header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
               header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
               header("Cache-Control: private",false);
               header("Content-Type: application/x-msdownload");
               header('Content-Disposition: attachment; filename="file.exe"');
               header("Content-Transfer-Encoding: binary");
               header('Content-Length: '.filesize($file));

    Open in new window

    LVL 17

    Expert Comment

    you can call this PHP file download.php

    Then you can call it like:


    test.txt could any name which exists in server.
    LVL 17

    Accepted Solution

    And see this:

    It's AS3 makes HTTP request and receives response

    Author Closing Comment

    Answer is too vague

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now