Download File in flash 8

  • ebodaddy
  • Newbie
  • Newbie
  • ebodaddy
  • Posts: 8

Post 3+ Months Ago

has anyone figured out how to do this, and if so can u share a .fla file?

Thanks!
  • Riptcage
  • Novice
  • Novice
  • Riptcage
  • Posts: 18

Post 3+ Months Ago

Um, can you be a tad bit more clear on the problem?

Do you mean Upload file using Flash?
  • ebodaddy
  • Newbie
  • Newbie
  • ebodaddy
  • Posts: 8

Post 3+ Months Ago

ok, sorry about that. How do you force a file download within Flash 8?

For instance, if I had a .jpg and I clicked the my download button it would open up the file browser, instead of opening the jpg inside the browser window.

I've tried researching it, but all I've seen is how to file upload into flash. Thanks for any help you may have.
  • Riptcage
  • Novice
  • Novice
  • Riptcage
  • Posts: 18

Post 3+ Months Ago

So let me see if i get what your trying to say..

Lets say im viewing a flash project, the project being the .swf file. It shows a jpg and you want to click the jpg so you can download the jpg file?

You said you want the file browser to pop up after clicking 'mydownload'.
You mean the file browser to browse through your files? that would be for an upload.. and that also involves some php scripting.

I just still don't understand what you really want to do..download a file within flash..meaning clicking on some download button within the .swf file so you can download something?
  • ebodaddy
  • Newbie
  • Newbie
  • ebodaddy
  • Posts: 8

Post 3+ Months Ago

Let's say this is my flash presentation, I want my download button to save the jpg to the computer, like it would if you were to right click it in your browser, and save image as. a separate window opens allowing you to specify where to save it, instead of the jpg just opening up in a new page of Internet Explorer, or whatever browser you are using.
Image



An example of how i would like it to download.
Image
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

force download
  • ebodaddy
  • Newbie
  • Newbie
  • ebodaddy
  • Posts: 8

Post 3+ Months Ago

Thanks once again IceCold.

For those who have thise same question here's how to do it.

in flash link to a php file that's in the same directory as the file you want to download
here is the code you u se in the php file
<?php
header('Content-disposition: attachment; filename=filename.jpg');
header('Content-type: image/jpeg');
readfile('filename.jpg');
?>

it has to be exactly like that
and the content type is different depending on what kind of file you are using. but image/jpeg works for this instance since i am downloading a jpeg file.
  • James R
  • Newbie
  • Newbie
  • James R
  • Posts: 6
  • Loc: Dublin

Post 3+ Months Ago

For some reason this isnt working for me..

I just get:

The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.


I have the fgollowing code on my button:

dl1_btn.onRelease = function(){
getURL("Mixes/triggerjanmix.php");
};

and in my php file i have:

<?php
header('Content-disposition: attachment; filename=trigger--januarys_blue[jan_07].mp3');
header('Content-type: audio/mp3');
readfile('trigger--januarys_blue[jan_07].mp3');
?>

Any ideas as to what i'm doing wrong?

Thanks
James.
  • James R
  • Newbie
  • Newbie
  • James R
  • Posts: 6
  • Loc: Dublin

Post 3+ Months Ago

ps - the php file is located in the Mixes folder and is being called correctly in the browsers address bar.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

you test this on your own comp or on a server?
if so, does it have php support?
  • James R
  • Newbie
  • Newbie
  • James R
  • Posts: 6
  • Loc: Dublin

Post 3+ Months Ago

On the server. I was thinking that in the back of my mind. I didn't pick the server originally so not sure if it supports php... I'll go have a gander.

Thanks Icecold..
  • James R
  • Newbie
  • Newbie
  • James R
  • Posts: 6
  • Loc: Dublin

Post 3+ Months Ago

Can't seem to get in touch and find out if the server supports php, but I'm presuming it doesnt. Is there any other way around this force download issue?

Or sould I reluctently put the mp3 into a zip file.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

create a html page with this code inside it, place it on the server and see if it downloads it when u press the link:
Code: [ Select ]
<html>
header('Content-disposition: attachment; filename=filename.jpg');
header('Content-type: audio/mp3');
<body>
  <a href="trigger--januarys_blue[jan_07].mp3">download file</a>
</body>
</html>
  1. <html>
  2. header('Content-disposition: attachment; filename=filename.jpg');
  3. header('Content-type: audio/mp3');
  4. <body>
  5.   <a href="trigger--januarys_blue[jan_07].mp3">download file</a>
  6. </body>
  7. </html>

But, if you want dynamic links ... you will need a server side script.
  • James R
  • Newbie
  • Newbie
  • James R
  • Posts: 6
  • Loc: Dublin

Post 3+ Months Ago

hmm interesting, it opens up a blank page with the following on it:

"header('Content-disposition: attachment; filename=filename.jpg'); header('Content-type: audio/mp3'); download file"

And you can download from the link^
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

aah, i forgot about the <head> tag.
add it like this: <html><head>.......</head><body>
  • James R
  • Newbie
  • Newbie
  • James R
  • Posts: 6
  • Loc: Dublin

Post 3+ Months Ago

I'm getting this:

" header('Content-disposition: attachment; filename=trigger--januarys_blue[jan_07].mp3'); header('Content-type: audio/mp3'); download file "

:-S
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

did u use the head tag?
Code: [ Select ]
<html>
 <head>
   header('Content-disposition: attachment; filename=filename.jpg');
   header('Content-type: audio/mp3');
 </head>
<body>
  <a href="trigger--januarys_blue[jan_07].mp3">download file</a>
</body>
</html>
  1. <html>
  2.  <head>
  3.    header('Content-disposition: attachment; filename=filename.jpg');
  4.    header('Content-type: audio/mp3');
  5.  </head>
  6. <body>
  7.   <a href="trigger--januarys_blue[jan_07].mp3">download file</a>
  8. </body>
  9. </html>

for this u should only have: download file
  • Xarathal
  • Born
  • Born
  • User avatar
  • Posts: 3

Post 3+ Months Ago

By the way, you can also use the Flash "FileReference.download" method to download files, and you don't need any PHP. It's pretty slick:

public download(url:String, [defaultFileName:String]) : Boolean

Code: [ Select ]
import flash.net.FileReference;

var listener:Object = new Object();

listener.onSelect = function(file:FileReference):Void {
  trace("onSelect: " + file.name);
}

listener.onCancel = function(file:FileReference):Void {
  trace("onCancel");
}

listener.onOpen = function(file:FileReference):Void {
  trace("onOpen: " + file.name);
}

listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
  trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}

listener.onComplete = function(file:FileReference):Void {
  trace("onComplete: " + file.name);
}

listener.onIOError = function(file:FileReference):Void {
  trace("onIOError: " + file.name);
}

var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
var url:String = "http://www.macromedia.com/platform/whitepapers/platform_overview.pdf";
if(!fileRef.download(url, "FlashPlatform.pdf")) {
  trace("dialog box failed to open.");
}
  1. import flash.net.FileReference;
  2. var listener:Object = new Object();
  3. listener.onSelect = function(file:FileReference):Void {
  4.   trace("onSelect: " + file.name);
  5. }
  6. listener.onCancel = function(file:FileReference):Void {
  7.   trace("onCancel");
  8. }
  9. listener.onOpen = function(file:FileReference):Void {
  10.   trace("onOpen: " + file.name);
  11. }
  12. listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
  13.   trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
  14. }
  15. listener.onComplete = function(file:FileReference):Void {
  16.   trace("onComplete: " + file.name);
  17. }
  18. listener.onIOError = function(file:FileReference):Void {
  19.   trace("onIOError: " + file.name);
  20. }
  21. var fileRef:FileReference = new FileReference();
  22. fileRef.addListener(listener);
  23. var url:String = "http://www.macromedia.com/platform/whitepapers/platform_overview.pdf";
  24. if(!fileRef.download(url, "FlashPlatform.pdf")) {
  25.   trace("dialog box failed to open.");
  26. }

For more info on the download method, look up the FileReference class and look at the download method.

One thing to bear in mind: the url MUST be a http or https request.

Rock on,

--eric
http://www.thecosmonaut.com
  • musik
  • Legend
  • Super Moderator
  • User avatar
  • Posts: 6893
  • Loc: up a tree

Post 3+ Months Ago

IceCold wrote:
create a html page with this code inside it, place it on the server and see if it downloads it when u press the link:
Code: [ Select ]
<html>
header('Content-disposition: attachment; filename=filename.jpg');
header('Content-type: audio/mp3');
<body>
  <a href="trigger--januarys_blue[jan_07].mp3">download file</a>
</body>
</html>
  1. <html>
  2. header('Content-disposition: attachment; filename=filename.jpg');
  3. header('Content-type: audio/mp3');
  4. <body>
  5.   <a href="trigger--januarys_blue[jan_07].mp3">download file</a>
  6. </body>
  7. </html>

But, if you want dynamic links ... you will need a server side script.


What happens with the header code if you have more than one file you want to allow people to download, say 40 or so?

Cheers.

Post Information

  • Total Posts in this topic: 19 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.