Download via Flash

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neliy
    New Member
    • Jun 2007
    • 32

    Download via Flash

    Hey there. I need to add a link in my current project from which the user will be able to download some images. I tried to find a tutorial to find the way or an actionscript example but I couldn't. Can someone help me plz? thnx
  • xNephilimx
    Recognized Expert New Member
    • Jun 2007
    • 213

    #2
    Hi, neliy.
    I don't anderstand what are you trying to do... You mean, adding a link that when the user clicks it it is promped to download the file (without givin the option to view it)?

    Kind regards,
    The_Nephilim

    Originally posted by neliy
    Hey there. I need to add a link in my current project from which the user will be able to download some images. I tried to find a tutorial to find the way or an actionscript example but I couldn't. Can someone help me plz? thnx

    Comment

    • neliy
      New Member
      • Jun 2007
      • 32

      #3
      Originally posted by xNephilimx
      Hi, neliy.
      I don't anderstand what are you trying to do... You mean, adding a link that when the user clicks it it is promped to download the file (without givin the option to view it)?

      Kind regards,
      The_Nephilim
      Exactly what you said. The images are already viewable by thumbs and by clicking on it I need the download file window to appear in order for the user to get the image. Plz help

      Comment

      • xNephilimx
        Recognized Expert New Member
        • Jun 2007
        • 213

        #4
        Oh, ok.
        That can be done only server side, in my case php. There's no way to do it client-side.
        The getURL method in ActionScript should read this for example:
        [CODE=actionscri pt]
        getURL("downloa d.php?f=path/to/image.jpg");
        [/CODE]
        the download.php is the php file that will handle the file to be downloaded, the f=path/to/image.jpg is a variable f being passed in GET method to the donwload.php file, so it will know which file must be used and where it is.

        The code in php should be like this:
        [PHP]
        <?php

        $thefile = $_GET['f'];
        $ext = substr($thefile ,-3);
        if($ext == "jpg") $ext = "jpeg";
        header('Content-type: image/' . $ext);
        header('Content-Disposition: attachment; filename="' . $thefile . '"');
        readfile($thefi le);

        ?>
        [/PHP]

        The first line, just catches the f parameter passed through the URL (GET method) and stores it in the $thefile variable.
        The second line extracts the last 3 characters -the extension of the file- and stores it in $ext.
        Then if the extension is jpg it changes it to jpeg because when we define the content-type, the jpg content-type is image/jpeg, but the rest could be image/gif and image/png if those where the cases.
        So then we define the actual content-type, then the content-disposition, that is how will be the content treated as, in this case like an attachment, adn we pass as the filename prameter the file that was passed from flash.
        Then we output the file with the read function, that way our php file "becomes" the image to be downloaded.
        The browser then will prompt the user to download the file.

        Kind regards,
        The_Nephilim

        Originally posted by neliy
        Exactly what you said. The images are already viewable by thumbs and by clicking on it I need the download file window to appear in order for the user to get the image. Plz help

        Comment

        • neliy
          New Member
          • Jun 2007
          • 32

          #5
          That was more than I was expected! your a legend! thank you

          Comment

          • xNephilimx
            Recognized Expert New Member
            • Jun 2007
            • 213

            #6
            LOL! You're welcome!
            Glad it helped you.

            Best regards,
            The_Nephilim

            Originally posted by neliy
            That was more than I was expected! your a legend! thank you

            Comment

            • lavertyj
              New Member
              • Nov 2006
              • 1

              #7
              This is awesome. I was looking for a way to do this as well. I am using it to download an xml file. The person can then make changes and upload it again. The problem I am having is that safari will not let the xml file download. Works fine in firefox though. Any ideas to make this work in safari.

              Comment

              Working...