Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allowing users to download text files 1

Status
Not open for further replies.

carmenMiranda

Programmer
May 22, 2003
47
GB
Now this may be a really stupid question, but I want to provide users with the facility to download text files from with a Flash interface.

The idea is that the user selects which file they would like from a menu, hits a 'download file' button and the file transfer begins.

Setting up the menu system and button is no problem, but despite searching through the language reference, I seem unable to find a function/method that will allow the download to start.

I originally thought that I could use the fscommand to communicate with the browser (and ultimately the server holding the text files), but have been completely unable to make this work.

Am I thinking along the right lines here or barking up completely the wrong tree? Any help would be much appreciated.
 
PHP CODE

Put this in a .php file

Code taken from php.net and modified slightly
Code:
<?php
//get filename
$fn = $_GET['filename'];

// We'll be outputting a txt file
header('Content-type: text/plain');

// It will be called downloaded.txt
header('Content-Disposition: attachment; filename="$fn"');
?>
FLASH CODE

Download button code:
Code:
btnDownload.onPress = function(){
  getURL("download.php?filename=somefile.txt", "_blank");
}

Then just have a button with the instance name of btnDownload.

This is just a basic script which you could improve for different file formats if you so wish.

Let me know if you have any problems!

Regards,

Martin

Computing Help And Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top