Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)

Reply
 
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Old 01-31-2003, 08:43 PM   #1
Graphfixz
Registered User
 
Join Date: Jan 2003
Posts: 41
Send a message via AIM to Graphfixz
Default Force File Download

Has anybody had any success in forcing Flash MX to display a download/save window to allow users to downlaod a file?


THanks in advance!
Graphfixz is offline   Reply With Quote
Old 01-31-2003, 08:53 PM   #2
freddycodes
Master of Nothing
 
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468
Default

Flash MX cannot do this alone, but in conjunction with a server side scripting language it is quite easy. What server side scripting languages do you have available to you?


In PHP you can use
PHP Code:
<?php
    
//Set this to the base of where files 
    //can be downloaded from for security measures.
    
$basedir "D:/wwwroot/";
    if(!
$_GET['file']) {
        print 
"Sorry that file does not exist";
        exit;
        }
    elseif(!
file_exists($basedir.$_GET['file'])) {
        print 
"Sorry that file does not exist";
        exit;
        }
    else {
        
header("Content-Type: octet/stream");
        
header("Content-Disposition: attachment; filename=\"".$_GET['file']."\"");
        
$fp fopen($basedir.$_GET['file'], "r");
        
$data fread($fpfilesize($basedir.$_GET['file']));
        
fclose($fp);
        print 
$data;
    }
?>

And in Flash

ActionScript Code:
getURL("dl.php?file=chat6.zip", "_self");
freddycodes is offline   Reply With Quote
Old 07-24-2004, 09:45 PM   #3
Vman
back from the dead
 
Vman's Avatar
 
Join Date: Mar 2003
Location: Chicago
Posts: 496
Default

I've tried using this instead of making the user open a pop-up image and doing a right click>save as. What do I have to change on here or replace for the $basedir to get it to work. All I've been getting is "Sorry that file does not exist". Thanks.
__________________
If it's stupid and it works, it's not stupid.
Vman is offline   Reply With Quote
Old 07-24-2004, 10:09 PM   #4
Vman
back from the dead
 
Vman's Avatar
 
Join Date: Mar 2003
Location: Chicago
Posts: 496
Default

I've been playing around with this on my local server and no matter what I put in for $basedir=""; and no matter what I put in for the file name on the button AS, the download dialog box opens and wants to save dl.php. What am I doing wrong here? Here's the code on the button:
PHP Code:
on (release) {
    
getURL("dl.php?file=bg4.jpg","_self"); 
}
 { 
__________________
If it's stupid and it works, it's not stupid.
Vman is offline   Reply With Quote
Old 11-22-2004, 11:25 PM   #5
djwesters
Registered User
 
Join Date: Nov 2004
Posts: 8
Question problem with force download timing out

I have managed to get the forcedown load to work with this script, but when i try and download a large file from my website it completes before it has finished downloading. Always after taking just under 5mins. So it seems as though it is timing out????? I'm using PHP 4.3.9 and IIS 6.0
djwesters is offline   Reply With Quote
Old 12-01-2004, 07:44 PM   #6
xeb
Registered User
 
Join Date: Nov 2004
Posts: 11
Default

i've tried using the code above and all it does is open the file in the new window

google found me another version which i've tried:

Quote:
<?
// downloading a file use http://somewhere.com/download.php?filename=name of file

$filename = $_GET['file'];
if(!$filename){ echo "ERROR: No filename specified. Please try again."; }
else {

// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache

// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

// use the Content-Disposition header to supply a recommended filename and
// force the browser to display the save dialog.
header("Content-Disposition: attachment; filename=".basename($filename).";");

header("Content-Transfer-Encoding: binary");

$root_path = "./audio/";

$myfile = $root_path . $filename;

//header("Content-Length: ".filesize($myfile));

readfile("$myfile");
exit();
}

?>
but with this i get the same problem - file opens in my new window. if i do it with a text file i get the text... try it with anmp3 and i get screeds of gibberish so i guess its displaying the mp3 as if it were a text file

can anyone help please?????
xeb is offline   Reply With Quote
Old 12-01-2004, 07:53 PM   #7
Neil Davidson
Registered User
 
Join Date: Dec 2004
Posts: 141
Default

I'm assuming you don't wish the pop - up window? I'm not certain how to contend with that.

As for the inability to finish a download : check server settings on client session max time. Or start a new session variable with your ASP, PHP, etc.
Neil Davidson is offline   Reply With Quote
Old 12-02-2004, 08:55 AM   #8
xeb
Registered User
 
Join Date: Nov 2004
Posts: 11
Default

pop-up wiondow is fine.... from what i gather about this method a pop-up is needed (either that or its opening in the main site window which is worse).... my problem is that its not doing what it should, ie, bringing up the save as dialog from that new window
xeb is offline   Reply With Quote
Old 12-02-2004, 09:29 AM   #9
djwesters
Registered User
 
Join Date: Nov 2004
Posts: 8
Smile asp.net

I got the php script to work, but it kept timing out after 5 mins and dropping the download before it finished, in the end I used a ASP.NET script which works perfectly, here it is.

in flash use :-

this.video1990Btn.onRelease = function() {
getURL("download.aspx?file=video/Finals 1990.avi");
}


create a file called "download.aspx" and insert the code bellow.

Code:
<%@ Page language="vb" runat="server" explicit="true" strict="true" %>
<script language="vb" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
	Dim strRequest As String = Request.QueryString("file")
	'-- if something was passed to the file querystring
	If strRequest <> "" Then
		'get absolute path of the file
	    Dim path As String = Server.MapPath(strRequest)
		'get file object as FileInfo
		Dim file As System.IO.FileInfo = New System.IO.FileInfo(path)
		'-- if the file exists on the server
		If file.Exists Then
			'set appropriate headers
			Response.Clear()
			Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
			Response.AddHeader("Content-Length", file.Length.ToString())
			Response.ContentType = "application/octet-stream"
			Response.WriteFile(file.FullName)
			Response.End
		'if file does not exist
		Else
			Response.Write("This file does not exist.")
		End If
	'nothing in the URL as HTTP GET
	Else
		Response.Write("Please provide a file to download.")
	End If
End Sub
</script>
djwesters is offline   Reply With Quote
Old 05-11-2005, 07:55 AM   #10
hardcore_gym
Registered User
 
Join Date: May 2005
Posts: 9
Default aspx script

hi

im using the same asp.net script you used to download files from my .exe file, however when i hit my button for it to download, it downloads the aspx file that i created, not the PDF file that i want to download.

is there anything in the aspx script that states which file it downloads that i need to change or is it all in the flash script that i put onto the button. if you could help me that would be great.

thanks

Hardcore_gym
hardcore_gym is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:04 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.