FileReference Source

Better late than never!

I’ve finally got round to creating 2 seperate examples that i can provide the source for. There’s a upload example, and a download example using the FileRefence object in Flash 8.

You can download the source from the download example or from here.

You will need to set the file permissions on the ‘uploadedFiles’ folder included when uploaded to you server so that it will accept uploads.

201 Responses to “FileReference Source”

  1. jason says:

    Are these working examples I cant see anything on the download example and cant get anything to show up on my download section.

  2. Tink says:

    Yes these are working examples are you sure you have the Flash 8 player?

    In the download example you should see a TextArea, a ProgressBar and a Button. On clicking the button it will open as OS window so you can select a directory to save the file. You will then download FileRefence.zip which contains the source for both examples.

    In the upload example you should see a TextArea, a ProgressBar and 2 Buttons. You click on the browse button to select a file on your local system to upload. You then click the upload button to upload this file to a directory on my server (this doesn’t load back into the player, but trust me it saves to a directory i specified).

  3. jason says:

    I thought the download section was supposed to list all the files from the download section and let you choose them, then download them. Like the oinam one.
    I used your php code for the upload section of the oinam one but cant get the download section to work, and thought yours might shed some light but it doesnt.

  4. Tink says:

    Nope the FileReference object doesn’t have any methods to return a list of files in a directory on your server.

    I presume Brajeshwar has some server side script that is able to return the list of files in a directory, or when a file is uploaded he is saving that data somewhere.

    Whats the problem with your download?

  5. jason says:

    fair enough, ya brajeshwar uses coldfusion but it doesnt work with my server that im on. So im using php, only the upload script works, the viewfiles doesnt,

    im using viewfiles.php with this script do you find anything wrong

  6. Jan says:

    I dont know how can I simply add progressbar to download.
    I have my site here: http://kameny.bresco.cz/
    If you click “Stahnout cenik” it will download the pricelist.
    I dont know how to apply progressbar to see download progress.
    Thank you

  7. Tink says:

    Jan

    Both the download and upload examples in this post use the ProgressBar component. All the source is available.

  8. Tink says:

    Jason, the following PHP works fine for me

    [php]< ?
    $xmlOutput = '~?xml version="1.0" encoding="UTF-8"?^~row^';
    $handle=opendir("uploadedFiles/");
    while ($file = readdir($handle)) {
    if(!is_dir($file) && !is_link($file)) {
    $xmlOutput .= '~file name="' . $file . '" size="' . filesize("uploadedFiles/" . $file) . '" path="uploadedFiles/' . $file . '" /^';
    }
    }
    $xmlOutput .= '~/row^';
    echo $xmlOutput;
    ?>[/php]

    you will need to change all instances of the text ‘uploadedFiles’ to match the path to the directory you want to view.

    you can view the output of the file here

  9. Tomas says:

    Hi, is there any way how to pass some variables with the file upload to the server side script? I would like to make comments TextBox in Flash and pass its contens into database table along with the file binary data. I would appreciate help very much.

  10. Tink says:

    Nope unfortunately that isn’t possible. You will have to invoke a seperate server side script to add the data to the database once the file has uploaded.

  11. Tomas says:

    Actualy this is possible, for instance pass variable as query string along with path to the server side script, but this does not work for Mozilla…So I was wondering if somebody has some interesting idea…

  12. Aaron says:

    Can you preview the thumbnail before uploading?

  13. Tink says:

    Hi Aaron

    No its not possible to have access to the location of the file that has been selected by the user to upload. This is a built in security restriction. Once the file has been successfully upload you can obviously load it back into the player so that it can be viewed. Also any file your downloading can be loading into the player before downloading as long as its a compatible format.

  14. gigi says:

    The up/down examples don’t work for me either

  15. a little noob says:

    how to do with asp file??

  16. Mark says:

    Hi, I am having no problems with the upload in php, however when I try to write an uploader in Ruby I get a litle problem with the content type. I am trying to store the file directly to the database as a blob and when I pull the content_type from the Filedata it returns:

    “application/octet-stream”

    instead of a image/jpeg that I was expecting. Have you seen this happen before?

  17. Bill Herr says:

    Please Help!!

    How can I get a selected file’s full path when using the
    fileReference?

    Thanks in Advance.

    Bill Herr

  18. Tink says:

    Hey Bill

    This is not possible due to security issues. If you want to show the image in the player you must upload it to your server first, then download it into the player.

  19. Rich says:

    The restriction on the path seems a bit much. I’m working on a file upload app dealing with tens of files at once that the user may or may not want to upload after all (many of my target users are on modems). Viewing the images before uploading is essential. Besides, I want to use a fade-in effect on a thumb nail of the image while it’s uploading.

    Surely there’s got to be a way. All you need is the path of the file. Hrmmm…

  20. Tink says:

    This is definately not possible with Flash alone, though you may be able to do it with a thrid party tool if your creating a standalone app.

  21. I also oneself something would want to find out on this theme. Very attentively I will read every post.

  22. Stef says:

    Hi,

    Great example !
    Just one question : how could I set the upload directory in upload.php with a variable ?
    I hope my question is clear because poor english :-)

  23. Tim says:

    Stef- did you ever figure out how to set the upoad directory in the php with a variable?

    I need to do something similar

    thanks

  24. Tink says:

    I don’t believe this is possible as you can’t send vars along with the upload.

  25. Ben says:

    @ Tink

    Your last comment just saved me a lot of shouting, so thank you. Has this been acknowledged by Adobe/MM?

    It’s a shame you can’t send variables with the upload as this would make swapping images onRelease pretty easy:

    var id = thisPhoto.id;
    var url = “saveJPG.php”;
    target.upload(url+”?id=”+id);

    unlink(‘photos/’ . $id . ‘jpg’);
    savePhoto($_FILES['Filedata']['tmp_name'], ‘photos/’ . $id);

  26. Mark says:

    Hi,

    Has anyone here got it running under ssl?

    I have tried everything (changing all html tags to https etc… etc..)

    Currently i just get it saying “upload started” and then it sticks at that.

    I would b grateful to anyone who could help :-)

    Many thanks

    Mark.

  27. owlbino says:

    Hey,
    I’m also trying to figure out a way to put password security on the file uploader flash page so that I can restrict who uses the php file. I mean, I know you can restrict access on the php side by only allowing certain IP addresses to upload, but that’s not the best solution. Thanks to anyone who can help.
    -Brian

  28. Tink says:

    I don’t belive this is possible for upload

    From the help

    Note: If your server requires user authentication, only SWF files running in a browser–that is, using the browser plug-in or ActiveX control–can provide a dialog box to prompt the user for a user name and password for authentication, and only for downloads. For uploads that use the plug-in or ActiveX control, and for uploads and downloads that use the stand-alone or external player, the file transfer fails.

    Live Docs.

  29. Ax says:

    How possible would it be to be able to select a folder and the flash script would upload the entire content of that folder?

  30. Tink says:

    It is not possible to select a folder. You could use FileReferenceList and selected all the items inside a folder, but you cannot select a folder.

  31. aran says:

    Does anybody know if you can send response variables back from the server side script (like loadVars) ?

    BTW – adding vars through the querystring works just fine for me in mozilla (firefox)

    (captured from service capture)

    (request)

    POST /fileupload.jsp?id=snapshot.jpg.1145317714328 HTTP/1.0

    (result – I am attempting to return a var from the server response – a temp file location with timestamp tacked on)

    &fileresult=http://telesto/upload/tmp/upload.snapshot.jpg.1145317714328.tmp

  32. barry says:

    Quick note: passing variables across in the url like:

    pic_obj.upload(“php/file_upload.php?myvar=” + var);

    and using $_GET does not work in Safari. Dam. I guess Ill be using a second php script onComplete.

  33. Jim says:

    Hi
    Need a bit of help debugging the file reference example.

    I get a message saying
    upload successful
    ////////////////////////////////////////////////////////////////////////////

    but nothing was uploaded!!

    Any suggestions??
    Thanks in advance

  34. Jim says:

    just an addendum…I’ve added the upload folder ‘uploadedFiles’ and set all the permissions to full control for the upload folder..still no luck

  35. Tink says:

    Hi Jim

    I’ve sent you an email.

  36. Jonathan Layne says:

    Hi Tink, I have a question for you, I am using a web app with filereference and I can get everything to work perfectly together IF they are in the same folder, but I want to separate the swf from the php and upload folder. How can I do that?

    Here is what I have now, my flash in root:\swf and the upload folder “pics” and the php in root:\cgi–bin

    from flash I use this var imageFolder:String = “cgi-bin/pics/”;
    var uploadScript:String = “cgi-bin/upload.php”;

    and in php I call the file with $_FILES['Filedata']['name']

    I have tested the php script with another php “test” script and it works fine but not from flash

  37. i have already used player 8 for a long time, good!

  38. Xristoz says:

    i tried to use that download thingy but i failed …Unfortunately i am not so experienced but i opened the actionscript and changed the URL of the file name (to a local file ””’private static var URL:String = “\High Quality Pics\12a.tif”;
    ) and the name to use when it ask.
    I dont know if i should change something else then i published again the fla but i get OS failed to open…Maybe cause the files are locally ? i tried to use a url of macromedia but it stops the download due to security reasons

    Maybe this is more complicated than what i would want but the geturl() opens the pictures to the browser by default which is soemthing i would not like .

    Thanx in advance

  39. Tink says:

    You need to have the tge file you want to download and the SWF on the same server or have a cross-domain policy file in place.

  40. I tried to make download file across domain but it not working on Flash Player 9.
    Must I specify server-side policy files for permitting access to data?
    Have you experience with this?
    Strange for me is that the same code is working if I start the SWF localy.
    If I upload the SWF on the server, than the same code in not working.
    Thank you for tips or help

  41. Tink says:

    I’ve not played with it in Flash 9, but have you got everything running on the same domain?

  42. I unistalled FP 9, on FP 8 is the same problem.
    Please how must I specify the server-side policy files for downloading zip file from other domain?
    On domain eg. foo.com I have SWF whith download btn and on teh domain fooDown.com I have stored the ZIP file.
    Thank you.
    As I said if I test the same code in Flash 8 IDE the download is working without problem.
    Regards Jan

  43. Tink says:

    When using this method, consider the Flash Player security model:

    Not allowed if the calling SWF file is in an untrusted local sandbox.
    The default is to deny access between sandboxes. A website can enable access to a resource by adding a cross-domain policy file.

    So you need a cross-domain policy file on the domain that is hsting the file to download.

    Flash Player TechNote – External data not accessible outside a Macromedia Flash movie’s domain.

  44. OK, thank you I will try to set it. Regards Jan

  45. Hi Tink, FYI:
    I did it backwards, because I thought that the crossdomain.xml must be on the server where is the SWF placed. Now is working. Thanks. Regards Jan

  46. Tink says:

    Glad you got it working!

  47. I have one off topic q.
    What is your favorite flash forum, is any?
    What is your favorite flash book, is any?
    Thanks
    Regards Jan

  48. Zeus says:

    Hi everyone,
    I apologize for bringing problems and not solutions to this thread. I am working with a flash multiple-file uploader with a PHP server-side script. I can upload one large file (over 80 MB) or multiple small files ( less than 2.5 MB) with no problems. The problem comes when I upload two or more large files (over 8 MB). When I invoke the upload function, the computer freezes (actually freezez even the mouse) for about 10 min, then it would resume it’s operation and the upload process fails with this message “flash script running slow, computer might become unresponsive”. I have tried other flash uploaders found on the web, even the example in the Flash 8 help files, but I run into the same problem with multiple large files. Anybody ran into this problem before? Can anyone shed some light on this issue? Help is very much appreciated.

    Z

  49. Tink says:

    Are you uploading all the files at the same time (as in the docs?). If so, why not try uploading them one after the other.

  50. Zeus says:

    Hello Tink,
    I am selecting multiple files from a browse window, then I hit the upload button. the code puts the files in an array and uploads them one after the other, and it is the same in every example I have seen so far. It works great with small files (I can upload 20 at a time) but not with multiple larg files.

    Cheers

  51. Tink says:

    the code puts the files in an array and uploads them one after the other, and it is the same in every example I have seen so far.

    even the example in the Flash 8 help files

    The example in the Flash 8 files doesn’t upload them one after another, it tries to do them all at the same time

    ActionScript classes > FileReferenceList (flash.net.FileReferenceList) > onSelect (FileReferenceList.onSelect event listener)

    import flash.net.FileReferenceList;
    import flash.net.FileReference;

    var listener:Object = new Object();

    listener.onSelect = function(fileRefList:FileReferenceList) {
    trace(“onSelect”);
    var list:Array = fileRefList.fileList;
    var item:FileReference;
    for(var i:Number = 0; i < list.length; i++) {
    item = list[i];
    trace("name: " + item.name);
    trace(item.addListener(this));
    item.upload("http://www.yourdomain.com/");
    }
    }

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

    var fileRef:FileReferenceList = new FileReferenceList();
    fileRef.addListener(listener);
    fileRef.browse();

    So are u sure your doing them one at a time?

    Maybe you can create a post somewhere on a forum and link the files and i’ll take a look.

  52. Zeus says:

    Here is the link ( I provided the action script file in .txt formate if it helps)

    http://www.simmetria.ie/Tink

  53. Tink says:

    As you can see here you upload all the files at the sae time in a ‘for loop’.

    //upload ach selected file
    public function uploadFiles(){
    filesUploaded = 0;
    totalKilobytesToUpload=0;
    totalKiloBytesUploaded=0;
    disableWhileUploadContinues();

    var item;
    for(var i:Number = 0; i < filesToUpload.length; i++) {
    item = filesToUpload[i];
    item.addListener(fileRefListener);
    item.bereitsGeladen = 0;

    /**
    * Here is wehere u upload the files, all at the same time within this loop
    */
    if(!item.upload(pathUploadScript+"?uploadDir="+uploadDir)) {
    frWindow.content.feedback_txt.htmlText = "Upload dialog failed to open.";
    }
    }
    }

    You should try uploading one file at a time. Once one file is complete, check the lst of remaining files, if there are some, upload the next.

  54. Hi,

    I was reading your blod, which is being very useful to me thank you, and I’m developing a online photographic printing system that allows user to upload their images and order prints from it.

    But I’m having a hard time with the FileReferenceList and FileReference classes, is not that isn’t uploading, but I’m having no feedback on the files that have been uploaded.

    here is my code:


    //Allow this domain
    System.security.allowDomain("http://localhost/");
    import flash.net.FileReferenceList;
    import flash.net.FileReference;

    var listener:Object = new Object();

    // When the user selects a file, the onSelect() method is called, and
    // passed a reference to the FileReference object.
    listener.onSelect = function(selectedFile:FileReferenceList) {
    var list:Array = selectedFile.fileList;
    //var item:FileReference;
    // Upload the file to the PHP script on the server.
    //imagePane.contentPath = "./files/" + file;
    for(var i:Number = 0; i "+i+": "+selectedFile[i]+"\n"
    // Call the custom downloadImage() function.
    downloadImage(selectedFile.name);

    }

    var imageFile:FileReferenceList = new FileReferenceList();
    imageFile.addListener(listener);

    uploadBtn.onPress = uploadImage;
    //imagePane.addEventListener("complete", imageDownloaded);

    function uploadImage(event:Object):Void {
    imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
    }

    so what is worng with this? onOpen seems don’t work neither any FileReference events. I have feedback from onSelect and onCancel.

    Thanks in advance.
    Rogers

  55. sorry seem I paste the wrong code in the last comment

    here is it

    //Allow this domain
    System.security.allowDomain(“http://localhost/”);
    import flash.net.FileReferenceList;
    import flash.net.FileReference;

    var listener:Object = new Object();

    // When the user selects a file, the onSelect() method is called, and
    // passed a reference to the FileReference object.
    listener.onSelect = function(selectedFile:FileReferenceList) {
    var list:Array = selectedFile.fileList;
    //var item:FileReference;
    // Upload the file to the PHP script on the server.
    //imagePane.contentPath = “./files/” + file;
    for(var i:Number = 0; i “+i+”: “+selectedFile[i]+”\n”
    // Call the custom downloadImage() function.
    downloadImage(selectedFile.name);

    }

    var imageFile:FileReferenceList = new FileReferenceList();
    imageFile.addListener(listener);

    uploadBtn.onPress = uploadImage;
    //imagePane.addEventListener(“complete”, imageDownloaded);

    function uploadImage(event:Object):Void {
    imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);

    }

    function downloadImage(files:Object):Void {
    statusArea.text +=” “+i;
    var loader = new MovieClipLoader();
    loader.onLoadInit = function (targetMC)
    {
    statusArea.text += getProperty(targetMC,_width)+” “;
    finalXScale=100;
    imageXScale = getProperty(targetMC,_width);
    factorXScale=(finalXScale/imageXScale)*100;
    //statusArea.text += factorXScale
    targetMC._xscale = factorXScale;
    targetMC._yscale = factorXScale;
    targetMC._x = getProperty(targetMC,_x)+120;
    statusArea.text += getProperty(targetMC,_width)+” “;

    }
    loader.loadClip(“./files/”+file,_root.myMC1);
    //i=i+1;
    }

  56. Avi says:

    Great example….

    I converted the .as part about which file formats below… but it wont let me select any mp3 :(
    success = this._fileRef.browse([{description:"All Formats (*.jpg,*.jpeg,*mp3)", extension:"*.jpg;*.jpeg;*.mp3", macType:"JPEG;JPG;MP3"}, {description:"All Image Formats (*.jpg,*.jpeg)", extension:"*.jpg;*.jpeg", macType:"JPG;JPEG"}, {description:"AUDIO FILES (*.mp3)", extension:"*.mp3", macType:"MP3 Audio File"}]);

    any help ?

    Thanks

    Avi

  57. Tink says:

    Hey Avi

    What OS are you testing on. The macTypes don’t look correct to me (well in fact you have 2 different macTypes).

    if you are on a mac try MP2_, Mp3_ and MPG3.

    i put a list here http://www.tink.ws/blog/macintosh-file-types/.

  58. Avi says:

    Thanks for the response,, u do some great work..!

    amazingly i just changed it to
    success = this._fileRef.browse([{description: "Audio MP3 and Image Jpegs", extension: "*.jpg;*.mp3"}]);

    since i think its macTypes that i had problems with though I am using OSX Tiger…

    So here is another question :) Id like flash to append a random label to the filename so i can have it as a reference number and to stop confusion when people load up files with the same name….

    can u help with that?

  59. Wes says:

    In reference to the FileReference object causing you script to run slow.

    The FileReference object in flash seems to update every so many bytes rathar than on a timed interval. Thus if you are on a fast connection then your FileReference.onProgress could be called hundreds of times a second if you have a fast enough connection where if you have a slower connection you may find that it seems to update very slowly sometimes not even once a second.

    We discovered this in having a few different people test an upload script and noticed how the ones that were uploading much faster were the ones having the error where the ones that had a slower connection seemed to be using little or no CPU at all.

    In order to correct this problem we made a short little if statement inside of the onprogress and also a counter on a movie clip. The movie clip would only increment a variable once per frame. The on progress would check the counter in the movie clip agains a maxcount number such as 12 for 12fps. If the counter in the movie clip was greater than or equal to the maxcount then allow the onprogress code to run. If not then do nothing. If the onprogress code ran then it would reset the counter in the movieclip to 0 and start over. The would only allow the script in the onprogress to update once per second.

    We tried this and it worked great for both the slow and fast connections. Since the fast connections were now only updating once per second and the slow ones were still updating once per second.

    Anyway. I hope this helps.

  60. Mike DeMauro says:

    Your coding is excellent. I noticed how you externalized each component within a MovieClip class. Do you have more examples of your work?

  61. Tink says:

    Thanks Mike

    You could take a look at the files from my webDU presentation, and also the files that i did for the foed book Flash 8 Essentials’.

  62. emmaopeel says:

    Thanks for the great lesson in this…

    I am not a developer, and hence might phrase this question a little awkwardly. I am using your sample and testing it on my server — from my Mac (happy home office), my uploader won’t function, but from my friend’s PC (less happy office office) everything runs just fine.

    Where I believe I am getting caught up is in the file types that I am able to select from. Reading through your comments, I realize there might be a problem with using/specifying macType. The oddity here is that I have no problems on a non-Intel mac, but can’t get it to run on my Intel mac. Are macTypes different on Intel Macs, or is this a problem of a different Flash player for the browsers?

    In any case, many thanks for the instruction!

  63. Tink says:

    Hi emmaopeel

    Take a look at the post here, and more specifically Josh’s comment.

    Thanks for this list – this is great reference. One thing to mention though – not a files on your Mac will have these file types specified, so you may be excluding some vaild files. Here’s a little more long-winded explanation: http://www.joshbuhler.com/2006/05/30/mac-file-types-one-more-thing/

    I really don’t know if the mactypes are different, although i would very much doubt it.

  64. LEE says:

    Oye! Thanks Tink! I was getting an onIOError, then I moved the files to my localhost folder, and now I’m getting an onHTTPError: newsletter.jpg.

    Am I correct in believing I should be able to place all the files on my localhost, open it in Safari, and it should work?

    What should I be looking at in response to an HTTPError?

    Thanks!

  65. LEE says:

    du-du-duuuh.

    I missed the uploads.php file when migrating to the localhost….all is well now.

    THANK YOU THANK YOU! I’m learning FileReference at the moment, and this is the first working example I’ve come across. I’m so glad you chose PHP as the SSS. TY!!!!!!!

  66. fotios says:

    Hi Tink

    While executing a file upload, eventhough the file did not upload successfully, the onComplete handler is executed. Is there any way to send an error message from php if the file upload was not successful? If yes can I catch the error from the onComplete handler?

    thanks

  67. Tink says:

    Hey fotios

    When u say the file didn’t upload successfully you mean u can’t see the file on the server?

    I think I came across this a while back and it was due to the permissions on the directory not being set so that you can write to it.

  68. LEE says:

    I think new directory permissions need to be set to 0777, but I also thought they were set as such by default.

  69. Tink says:

    Should be 777. I guess it wuld depend on your server setup to what the defauklt is. It aint 777 on mine though ;)

  70. fotios says:

    Hi All and thank you for your replies.
    This was exactly the problem. The directory permissions.
    But my actual problem is that the onComplete handler of the Filereference has been executed allthough the file has not been copied on the server successfully. Like this the user will never know if the upload was successfull or not. Is it possible to send any error code from Php to flash for such upload failures and handle the error code inside the onComplete handler?

    thanks

  71. LEE says:

    Hey Tink,

    I’m unable to set the $storage variable as a new directory: $nudir = mkdir($name,0777);
    with $name being a $_POST['input'] from Flash.

    Any ideas?

  72. LEE says:

    Hrm, it doesn’t require a typecast…

  73. LEE says:

    oops, I was sending the $_POST['input'] variable after the FileReference upload event.

    I just created an .fla with your .as script, modified of course to remove the public/private/static syntax, and repeatedly get an onHTTPError now. I’m not sure why.

  74. LEE says:

    oh, there was that UploadExample.URL that needed to be removed. It works now…I’m a bit OOP-challenged ; }

  75. LEE says:

    Aye, I just don’t see how I can send other variables to the php script along with the fileRef upload.

    Is it not possible?

  76. Cale says:

    I’m a little new to Flash 8, so when I configured the UploadExample.fla and published it, everything worked fine.

    My problem is that I can’t find where all your action script is located in the .fla file to modify. I’m trying to change the uploader so that it takes mp3 files, not picture files.

    When I the .swf file in my html file, I’ll even put src=UploadExample.swf?file=UploadExample.as , yet the information in the Action Script file doesn’t actually take in the swf presentation.

    Am I just missing something small in Flash 8 editor that directs me to the action script you input in the .fla file, or do I need to direct the .swf file another way? When I go to “Actions” on every layer of the .fla file, there’s nothing there. It makes me wonder where all this action script is that makes it work in the first place. :-)

    Thank you.

  77. Tink says:

    Hey Cale

    The ActionScript is in the external AS files. You would need to edit the AS file, then republish the flash movie so that it compiles the changed code to output a new SWF.

    Hope that makes sense.

  78. FreshFarhan says:

    Thanks a lot tink this flash solution is really a better alternative to file uploading via ajax… does the same thing in a really better way, and has the progress bar too! Thanks a lot great work really appreciate it

  79. Steve says:

    Tink, I hope you can help me. I love the example of your upload file. Have copied over to my server and it appears to run OK through a browser in that i get a “upload successful” message but there is nothing on my server. I am running Win2003 server, IIS6 and PHP5. I have checked the permissions on my folders and they are set to read/write. I have placed the folder uploadedFiles as a sub folder of upload which stores your files.

  80. Tink says:

    Hey Steve

    If yuo changed the directory where the file gets uploaded to, you need to change the PHP so that it targets the correct directory

  81. Chris says:

    Tink, on May 24th, 2006 Jim posted a comment about uploaded files now showing up when the upload success was displayed. I’m having the same issue. You sent him your response by email, I was wondering if I could have the same courtesy. Thanks in advance.

    Chris

  82. Tink says:

    Hi Chris

    I’m not sure what i replied. Have you got the permissions on the target directpry set to 777?

  83. Chris says:

    I was chmod(ing) the permissions, turns out i needed the network administrator to change them for me. Thanks!

  84. tom says:

    i’m having some problems with getting the flash uploader to work fully. when i upload a file, it starts to upload, but when it reaches 100%, i get an onHTTPError. i chmoded the folder to 777 and the directory matches the php file, not sure where the problem could be. any suggestions?

  85. Tink says:

    you know what HTTP error u get?

  86. tom says:

    i get this error:

    onHTTPError: picture01.gif

  87. tom says:

    i forgot to mention, the file itself never uploads either

  88. tom says:

    i get an HTTP error #403 using another flash uploader

  89. Hi Tink how can I unsubscribe from this post?
    If I click in my email the link for unsubscribing I get message on you site:

    Sorry, no posts matched your criteria.

    Unsubscribing do not work for me:
    http://www.tink.ws/blog/wp-subscription-manager.php?email=kratochvil@flashmedia.cz&key=e60e662b7af6096582518b1e01165f58

    Thanks

  90. Martin says:

    Hi Tink,

    Great work on the script its great.

    When I upload it all goes fine, but all the files have a CHMOD of 600 and an owner of Apache and I can’t change any settings as I get a not allowed error.

    thanks in advance

    m

  91. LEE says:

    The upload example works beautifully! Locally the download example returns:

    OS window failed to open
    ////////////////////////////////////////////////////////////////////////////

  92. LEE says:

    And that is because you have to specify an actual http:// URL, can’t be a local name silly = ]

  93. Mrgee says:

    I am a little confused by the sandbox security. I want to be able to offer a file upload facility, so people can upload files to my website. I have tries the above code, and get a sandbox security error. I have a crossdomain.xml file on my server allow access from all doamins. I have a line of code in the actionscript that also allows all domains. Why am I still receiving this sandbox error..?
    Thanks..

  94. Tink says:

    Does it work for you when uploading to the same domain Mrgee?

  95. Ant says:

    Looks like the flash uploader doesn’t bother to validate the php’s reply. The php sample replies “1″ if moving is successful and replies “0″ otherwise.

    I tried echoing “0″ no matter what but the flash uploader still shows a successful upload. How do we set it up so that the uploader actually recognizes the reply?

    I actually was hoping you had an answer for fotios’ question/s above.

  96. Frank Lindeskov says:

    I am not using your downloader code yet but the Adobe standart downloader code.
    I have a problem that it hangs on the onSelect statment!!
    The file works localy but not on server, all files is on the same domain.
    This is an ASP site.

    Have you got any expirence with that?

    Thank you
    Frank

  97. rod says:

    UploadExample works fine, however I can’t work out why I have to press the upload button twice on a mac G5 using firefox browser!

  98. TADAS says:

    Hi Tink, i’m a young music producer and i’m bilding my first website. Its allmost done. But i’m having some problems with my download section. Your example works very nice. But only with one file. Maybe i need more experience to work with flash but i do not understand how to create a list of files that i want to let people download and listen. Please help. i need an axample that works with more than one file.

  99. Tink says:

    Frannk, sorry no experience with ASP.

    rod, i would love to find the time to have a look into this and do some testing. if i do i’ll definately post. if you make any progress please do feed some information back.

    TADAS ya need to use FileReferenceList. I believe Brajeswar has an example at http://blog.oinam.com/2005/08/flash-8-file-upload-download/

  100. TADAS says:

    Hi again, it apears that all example download links at Brajeswar are dead. Maybe You do have a copy??? Its realy important.

  101. Tink says:

    sorry no

    i would suggest u take a look at the help files under FileReferenceList.

  102. TADAS says:

    hi, finaly i completed the download list. The list itself works ok. But i have another problem. I created a scrolling list of my files. That for i use a mask. But when i use this mask the progress text line (“Downloading … %”) can not be seen. The mask does not let this text thru. Can You help me with that? I dont understand whats the problem. Thanx.

  103. LEE says:

    Components don’t function properly when placed inside a mask.

  104. Tink says:

    Hey TADAS

    This will be due to the font not being embedded.

  105. artfunction says:

    I also get an onHTTPError every time i try uploading, in both IE and Moz… any idea why this would happen? I have uploadedFiles set to 777…

  106. Tink says:

    Hi artfunction. You should get some details back from that error to narrow down he problem a little more.

  107. artfunction says:

    how do i get more info back from the error? it just says:

    onHTTPError: filename.jpg

    how do i get the actual http error code? much thanks!

  108. artfunction says:

    Im getting HTTP error 403… any idea why this would be occuring? It happens after the upload progress reaches 100%….

  109. Tink says:

    Sunds like the directory is writable or you have some password protection on the directory.

  110. artfunction says:

    I am using your uploadedFiles directory with perms set to 777 same with the perms set on upload.php [777]… no passwords or anything on the folders tho, i mean aside from the regular ftp-type password… ill try some other things, any other ideas though? do i need any crossdomain info? im not crossing any domains so i wouldnt see why… just grabbing at straws now :(

  111. Tink says:

    Can you FTP and image to the folder and then give me a link to it?

  112. artfunction says:

    update:

    ok figured it out: there are 2 ways to get around the error 403:

    1) add these lines to .htaccess

    SecFilterEngine Off
    SecFilterScanPOST Off

    2) modify upload.php to include the ftp username and pw

    move_uploaded_file($_FILES['Filedatá]['tmp_namé ],
    “ftp://user:pass@yourdomain.com/uploadDir/”.$_FILES['Filedata']['name'
    ]);

    … both methods have their advantages and disadvantages as far as security goes. Hope this helps someone! Thanks again Tink for your quick replies and AWESOME up/down example :) saved me hours of fiddling!

  113. artfunction says:

    one more question, is there anyway to redirect after the upload from the php? I tried using header(Location:) but it didnt work… its almost as if the upload success code in the php isnt even being called on success, it only calls the flash…. is there anyway to redirect to http://www.mypage.com from the php/js? I need to avoid using getURL or any type of flash-based redirection… what do you ‘tink’ ;)

  114. Tink says:

    Glad you got it sorted. So you did have the folder password proected (.htaccess).

    I don’t know enough about PHP to be able to help you out with the quest above, but I don’t think you can. If you really don’t want to call it from Flash you could invoke some JavaScript from Flash.

  115. artfunction says:

    the folder wasnt password protected- there was a default blank .htaccess in the root of the public_html folder. It didnt have anything in it [so it didnt pw protect anything] but by adding the above 2 lines to it i was able to eliminate the 403 error… weird. yeah i guess ill have to rig something up to get redirection working as i want it

  116. Jasmin says:

    I am only able to upload one picture only when i try to upload a few pictures only? Is there any code to put to upload all the pictures at a same tim.

  117. Tink says:

    @ Jasmin

    take a look at FileReferenceList

  118. Jasmin says:

    I try using the FileReferenceList but I got error when I compile. Can you please tell me what code i need to add from the original UploadExample.as?

  119. Jasmin says:

    Now currently from the codes that I download from this site I’m only able to download 1 picture. I am not able to download all the pictures when I select them. Please help me to solve this problem.

  120. artfunction says:

    Tink-

    Is there anyway to get the path to the file they have selected? Like c:\myfiles\myselectedfile.exe? I know about teh file.name property but im trying to get the full path not just the name…. thanks!

  121. Tink says:

    Nope, you cannot get the path for security reasons.

  122. Dave says:

    Is it not possible to pass a simple variable to the upload script so that an upload folder can be specified? I’m writing a backend tool in Flash and the user can select one of several folders on the server to upload into. If I can’t pass in a variable, is the best solution to stick the simple uploader script into each possible folder and then just call the script in the chosen folder? That’d work, but it’s certainly not ideal…

  123. Tink says:

    @ Dave

    Not it is not possible with AS 2.0, although this functionality was added to the AS 3.0 implementation.

  124. Dave says:

    Thanks much for the quick reply Tink. Good to know it’s in 3. I’ve just been so busy with F8 projects I haven’t had much time to work in 3 yet.

  125. Jasmin says:

    I try using the FileReferenceList but I got error when I compile. Can you please tell me what code i need to add from the original UploadExample.as?

    Now currently from the codes that I download from this site I’m only able to download 1 picture. I am not able to download all the pictures when I select them. Please help me to solve this problem.

  126. Jasmin says:

    I cannot seem to select multiple files to upload, I could only select one item at a time. How can I select multiple items at a time to upload.

  127. Jasmin says:

    I try to modify the code and now I’m able to select more than 1 files at a time and display it. But however when I try to click the upload button, it does not seems to work.

    I have paste the code below, can you please help me how to solve this problem:

    private function upload():Void
    {
    var success:Boolean;
    var filesToUpload:Array;
    var item;

    for(var i:Number = 0; i

  128. Jasmin says:

    private function upload():Void
    {
    var success:Boolean;
    var filesToUpload:Array;
    var item;

    for(var i:Number = 0; i

  129. Jasmin says:

    {
    item = filesToUpload[i];
    item.addListener(this);
    success = item.upload(UploadExample.URL);
    }
    //start upload process
    //success = this._fileRef.upload(UploadExample.URL);

    //if the upload process failed to start
    if(success == false)
    {
    this._textArea.text += “*****Upload Process Failed To Start*****\n”;

    this._textArea.vPosition = this._textArea.maxVPosition;
    }
    }

  130. Jasmin says:

    I can browse for more than one file now, and able to store the files selected onto the textarea. But now i cannot seem to upload.

    How do I make the upload function work?

    private function upload():Void
    {
    //start upload process
    success = this._fileRef.upload(UploadExample.URL);

    //if the upload process failed to start
    if(success == false)
    {
    this._textArea.text += “*****Upload Process Failed To Start*****\n”;

    this._textArea.vPosition = this._textArea.maxVPosition;
    }
    }

  131. Sonny says:

    Hi,

    Thanx for this example. But do you also have the example for the one on
    http://www.tink.ws/blog/filereference-example/ ?

    I would love to know how that one is made?

    Greetings

  132. Tink says:

    Hey Sonny

    You can download the source for this example and the other examples i did for the book at http://www.friendsofed.com/download.html?isbn=1590595327 (The files to accompany the book’s appendix ‘A’ (1.1 MB)).

    In fact didn’t I included the source in the download for that example?

  133. Rod says:

    I am using the UploadExample.fla successfully. However I am getting an HTTP error when I password protect the folder where the UploadExample.swf is. This error only occurs on OS X.

    Any php tips for MAC OS X allowing access to a folder protected by .htaccess ?

    many thanks,
    rod

  134. Tink says:

    @Rod

    This is from the docs

    The FileReference and FileReferenceList classes also do not provide methods for authentication. With servers that require authentication, you can download files with the Flash Player browser plug-in, but uploading (on all players) and downloading (on the stand-alone or external player) fails.

  135. Tink says:

    @ Rod

    Dan Wasyluk has a workaround for authorization here http://www.artfunction.com/hosted/thedanosphere//wordpress/?p=7

  136. [...] written an excellent tutorial to get you started with FileReference, it can be found here: Tink’s FileReference Tutorial + Source His example is great, it covers all th [...]

  137. LolitochkaBC says:

    Ааану-ка ребятки голосуем!!!

    Признавайтеесь проканзики и владельцы сайтп http://www.tink.ws ))))

    ЧТО вы будете делать этим летмо?!

  138. For those people struggling to pass variables from flash to PHP when uploading – you can pass variables on the ‘GET’ string of your PHP script. e.g. http://www.acme.com/upload.php?firstname=Joe&lastname=Bloggs

    Obviously this is not as useful as says loadVars since only a limited number of variables can be passed and they have to be URL encoded (escape() in actionscript) but it will probably be enough for most applications.

    To access the variables you append to the URL in PHP:

    $firstname = urldecode($_GET['firstname']);
    $lastname = urldecode($_GET['lastname']);

    You can then use these values in your scripts to handle the upload.

    HTH

  139. alltechneeds_com says:

    my upload script works great, the problem that I noticed, is that uploading multi small files at once (ie 40 pics) work without any hiccups.
    Now if one of this file contains apprx over 10mb its gives up on it, but uploads the rest.
    Now if I upload lets say 5 videos files that are 80mb each, it does the first 2 successfully, the rest get an IO error 2038?

    I’m using apache.org commons upload on the backend, does anyone know if this hiccup is coming from commons or just actionscript 3.0.
    I never had a problem with commons before since the old school way was uploading 1x.

  140. Inder says:

    Hello Sir

    I am using Flash 8.
    I have made a file uploading in flash by using PHP.
    i have put some extra code in the php file that updates XML file.

    My uploading works great but problem i am facing is that extra coding i put in PHP file to update XML file Does not works. on the otherhand if i call that PHP file from other Html file than it works well

    Plzz help me. I am totally confused..

    Inder

  141. Sam says:

    In response to Rod:

    “UploadExample works fine, however I can’t work out why I have to press the upload button twice on a mac G5 using firefox browser!”

    I’m having the same problem, only it’s not on Mac FF but on my Linux Firefox/Mozilla. I’ve tested on Windows’ Opera 9, Firefox 2, and IE7 and they all work. I have no idea why I have to click the upload button twice before the file is uploaded to the server if I use Linux Firefox/Mozilla.

    Anybody else had the same problem? How do you fix it?

  142. Joao Beca says:

    hi

    That tutorial is very good. As I don’t know php is anyway to use asp instead? Can you tell me what do I need to change on the php that change the sizes of the photos and change the name?

    Thanks

  143. Pete Spencer says:

    Hi, thanks for saving my sanity after days of trying to get Flash8 upload to work. I had to add: SecFilterEngine Off
    SecFilterScanPOST Off
    to the htaccess file and add a php.ini file to increase the servers upload limit. However I can’t get it to upload zip files. I’ve added *.zip to the .as file to no avail. Any ideas, please?

  144. Tink says:

    Can you not select the file, or can you select it but the upload fails?

  145. pete says:

    No, I can’t select a .zip file. I tried adding:
    {description: “Zipped Files (*.zip)”, extension: “*.zip”, macType: “ZIP_”}
    to the .as file, but no go.

  146. Tink says:

    Have a read here

    http://www.joshbuhler.com/2006/05/30/mac-file-types-one-more-thing/

    Basically if the file wasn’t created on a mac it may not have the macType added to the file.

  147. pete says:

    I’ve created a .zip file on my Mac and it still doesn’t see it. Any ideas?

  148. Rod says:

    The Fileupload example stopped working on my site. I had to get my domain host to deal with it, he eventually said this-
    “The error you are receiving is being caused because currently Flash contains a bug whereby when making a connection it does not properly transmit its’ header information, causing this to be cutoff before being fully delivered – Currently security software in place on our systems prevents broken connections of this nature due to the potential security implications of connections of this kind being made.
    I have however removed your /public_html/Static folder from the system’s security checks to allow your content within this folder to bypass these restrictions, and you should now be able to complete your connections correctly. Please note these errors are not being caused by a fault within your script, but rather one within the Adobe client software being used to make connections to the script.”

    hope this saves someone some headache.
    rod

  149. Huroman says:

    The script it doesn´t work in OS X (Mac)… only the uploader script.

  150. Tink says:

    @Huroman

    Not sure if your refering to the filetype filtering and therefore you can’t select the files you want? If so you just need to edit the filter.

  151. d4rklit3 says:

    So the problem I am getting w/ this script is that it will not work w/ ipowerweb’s hosting package when i use it w/ OS X, i get a 403 error, incidentaly when i test it on some local hosting company it works fine even on OS X, I dunno if it is the issue that Rod described with flash bug. I am not using any sort of authentication, the necessary files and folders just have CHMOD 757 set to them. I have tried everything short of what Rod just said, but b4 i go ahead and stay on hold w/ ipowerweb for like 2 hours I want to see if there is anything else that can be done.

  152. Avi says:

    For some reason when i upload large files eg. 80megs , It reports success… but the file is not on the server :(

    Works fine for small files… 6megs etc…

    Any reason for this?

  153. Tink says:

    he player offcially supports up to 100MB. You sure the files aint bigger or your server aint restricting you?

  154. Chris says:

    Is there a way to set what the max file size is for a file being uploaded? Can there be a check performed when the inital file is selected to warn if it exceeds the max file size?

  155. Tink says:

    Yep you can check the ‘size’ property.

  156. Chris says:

    Right. It’s not currently written in the AS correct? If I want to check it I’ll have to write a quick function to validate the size. Right?

  157. pig says:

    Hi!
    Fileupload works for me. But…
    I’d like to upload multiple files at in one go that come from different folders on the users computer to the same (php) script Would it be the same folder then FileReferenceList would be the choice.
    Is there a way to upload multiple files with additional formdata in one go?
    If FileReferenceList’s fileList property wouldn’t be read-only I could add FileReference objects manually then do the upload. But… FileReferenceList fileList __is__ read-only!
    Is there a solution to this problem or hsould I do the upload in multiple goes?

  158. Tink says:

    FileReferenceList uploads each file one at a time as fars as im aware, so you could create an array of FilereferenceLists, and once one is complete, start the next.

  159. el pedro says:

    hello and thanks for the example. but i have some issues. i tested the script on my own host and it didnt work. i got a “File does not exist:” 500 error. the file DOES exist and the write folder is 777. i have tried on another server and it works flawlessly. are there any particular settings my server should have to allow for the upload through flash so i wont have this issue? please help, im going nuts! thanks.

  160. Peter says:

    I have downloaded your sample and was able to get it to work successfully. I have also downloaded samples from Adobe and managed to get those to work as well. The only thing that I have changed is that I am using an ASP page to handle the uploading of the file. This part also works fine.

    What does not seem to work, no matter which sample I am using is the progress bar. It does track progress but it finishes long before the file is actually finished being written on the server. Does it behave this way when using PHP or does the progress bar truly indicate the status of the file on the SERVER?

  161. Antago says:

    I get “uploaded successfully”, even when the folder doesn’t exist. When the appropriate folder, designated in my upload.php, exists, it still has not written the file. Do I need to change permissions to any of these things?

    Thanks a lot! – Antago

  162. Ed says:

    First thanxs for the file uploader, it works great. My question to you is how can I call a javascript function from the onComplete method. I am trying to use ExternalInterface.call to send the fileref.name to a javascript function but nothing seems to happen. Here is the function which is just function with the external call in it.

    BTW. I have the script access to always and I import the external into the AS

    private function onComplete(fileRef:FileReference):Void
    {
    this._progressBar.setProgress(100, 100);

    var display = “display_return”;
    var returnValue = ExternalInterface.call(display).ToString();

    this._textArea.text += “upload successful ” + fileRef.name + “\n\n”;
    this._textArea.text += returnValue;

    this._textArea.vPosition = this._textArea.maxVPosition;
    }

    Any help you supply me will be greatly appreciated and thanks ahead of time.

    Ed

  163. Seba28 says:

    Hi, I also have a problem with filereference.. I created a script.. fairly simpel that on the hand of two dropdownboxes creates a filename and has to download that filename.. Everything works.. but only now and then.. it often stops on the Onselect or on the Onopen. Every now and then its starts downloading and then stops for now apparant reason. I do’nt understand what could be the problem
    [as]
    stop();
    popup_mc._visible = false;
    preloader_mc._visible = false;
    var typeWijz:Object = new Object();
    var dataWijz:Object = new Object();

    typeWijz.change = function(eventtype_obj:Object) {
    var typewz = eventtype_obj.target.selectedItem.data;
    fout_txt.text = “MAAK UW KEUZE!!!”;
    trace(typewz);
    };
    dataWijz.change = function(eventdata_obj:Object) {
    var datawz = eventdata_obj.target.selectedItem.data;
    fout_txt.text = “MAAK UW KEUZE!!!”;
    trace(datawz);
    };

    type_cb.addEventListener(“change”,typeWijz);
    data_cb.addEventListener(“change”,dataWijz);
    fout_txt.text = “MAAK UW KEUZE!!!”

    pdf_btn.onPress = function() {
    import flash.net.FileReference;
    fout_txt.text = “VOORBEREIDING DOWNLOAD”;
    var listener:Object = new Object();
    // preloader_mc._visible = true;
    listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
    trace(“onProgress with bytesLoaded: “+bytesLoaded+” bytesTotal: “+bytesTotal);
    preloader_mc._visible = true;
    A = bytesLoaded*100;
    B = bytesTotal;
    preloader_mc._xscale = A/B;
    fout_txt.text = “DOWNLOADEN !!!”;
    };
    listener.onHTTPError = function(file:FileReference):Void {
    trace(“onHTTPError: “+file.name);
    removeListener(listener);
    };
    listener.onSecurityError = function(file:FileReference):Void {
    trace(“onSecurityError: “+file.name);
    removeListener(listener);
    };
    listener.onSelect = function(file:FileReference):Void {
    fout_txt.text = “DOC GESELECTEERD”;
    trace(“onSelect: “+file.name);
    };
    listener.onCancel = function(file:FileReference):Void {
    trace(“onCancel”);
    popup_mc._visible = false;
    preloader_mc._visible = false;
    removeListener(listener)
    fout_txt.text = “DOWNLOADEN GEANNULEERD”;;
    };
    listener.onOpen = function(file:FileReference):Void {
    trace(“onOpen: “+file.name)
    fout_txt.text = “DOC ZOEKEN!!!”;;
    };
    listener.onComplete = function(file:FileReference):Void {
    trace(“onComplete: “+file.name);
    popup_mc._visible = true;
    popup_mc.gotoAndPlay(1);
    removeListener(listener);
    fout_txt.text = “DOWNLOAD OK”;
    };
    listener.onIOError = function(file:FileReference):Void {
    trace(“onIOError: “+file.name);
    popup_mc._visible = false;
    preloader_mc._visible = false;
    fout_txt.text = “HET SPIJT ME MAAR MOMENTEEL IS HET GEVRAAGDE NOG NIET BESCHIKBAAR!!!”;
    removeListener(listener);
    };
    var fileRef:FileReference = new FileReference();
    fileRef.addListener(listener);
    var url:String = (“http://www.x2o.be/pdf/”+data_cb.text+”_”+type_cb.value+”.pdf”);
    trace(url);
    if (!fileRef.download(url, data_cb.text+”_”+type_cb.value+”.pdf”)) {
    trace(“dialog box failed to open.”);
    }
    };
    [/as]
    Maybe i made a mistake somewhere?

  164. [...] n Script 3 geht, mein Kollege hat da ein tolles Buch. Jetzt bin ich durch Zufall auf einen Flash 8 File Uploader gestoßen. Mit Quelltext zum dran rum sc [...]

  165. Paul Steven says:

    I am experiecing a problem whereby the upload progress goes to 100% immediately. This is happening on other similar upload examples I have found on the web so I am thinking it is due to a problem with my setup.

    I am testing using Flash Player 9, Windows Vista Ultimate Firefox 2.

    I have also tested it on Flash Player 9, Windows XP, Internet Explorer 6

    Both suffer the same problem. Both have McAffee Antivirus if that could be an issue.

    Thanks

    Paul

  166. Tink says:

    Hey Paul

    Does the upload example on this post work for you? Sounds like its a problem with your folder permissions.

  167. Paul Steven says:

    Hi Tink

    Yes the upload example works in that it uploads the file. The problem is that it goes immediately to 100%.

    Whereas the download example displays the progress correctly.

    I have tried quite a few other similar demos online and I am experiencing the same problem. All I can think of is its a problem caused by anti-virus software as I have read about a problem similar here http://www.flashinto.com/forum/viewtopic.php?f=4&t=5179

  168. Tink says:

    Does your anti-virus block port 80? If so can you unblock it?

  169. Ed says:

    Hey Tink,
    This is my second time posting because I have no idea why I cannot access the fileref after it has been uploaded. The upload works great but I am trying to use ajax to update a image after it is uploaded. I have tried to use ExternalInterface.call in the OnComplete method but nothing happens. Any ideas on why I cannot use a callback function after completion.

    private function onComplete(fileRef:FileReference):Void
    {
    this._progressBar.setProgress(100, 100);

    var display = “display_return”;
    var returnValue = ExternalInterface.call(display).ToString();

    this._textArea.text += “upload successful ” + fileRef.name + “\n\n”;
    this._textArea.text += returnValue;

    this._textArea.vPosition = this._textArea.maxVPosition;
    }

    Ed

  170. Antago says:

    Okay I got this thing to work. I wish I could unsubscribe to notifications of responses, though. I tried it said no page exists :(
    thanks a lot for this script!

  171. Tink says:

    @ Antago

    Yeah i don’t know why you can’t and how I can rectify it :( .

    Any tips would be useful.

  172. Paul Steven says:

    I have looked into whether my anti-virus blocks port 80 and I can find no settings related to blocking ports. However my antivirus settings are not easy to access so it may be in there somewhere…

  173. lepep says:

    Hi Tink,… i have a problem,… I tried some upload tutorials, they works fine and your too,… i tried 5 different servers from different companies, everywhere works fine, but only on one strange server it doesnt work,… HTTP Error 403,… i do not know how to figure out it,… i tried some uploads without AS and flash, they works fine. If i try use upload of combination AS and PHP that is broken :( ((( can you look at server configuration to see what i cant? http://www.dnaproduction.sk/infophp.php

  174. Tink says:

    @ lepep

    403 is a forbidden error. You sure your the target folder is writable?

  175. lepep says:

    777 :( ,… it is strange,…

  176. Activeideas says:

    we can pass var on same time while uploading file throught flash see details here http://www.activeideas.net/article/FileReference

  177. .lunatick says:

    Hello everybody,

    I’m experimenting with FileReference, and I was wondering how I can get the download to work with files that are on a server that needs authentication.
    I let the user log onto a Flash-website (same login and pass, so I already have that data), but I want them to be able to push a button that automatically lets them download a file on a different (protected) server.

    I’ve tried by using
    fileRef.download(http://login:password@www.site.com)
    but that didn’t work… :)

    If i try it on a server that doesn’t need authentication (without the login:password@-part), it works… I just don’t want the user to enter their login again…

    Any ideas?

  178. Thank you so much for this source code. I’ve been trying to get this to work for ages. Cheers!

    truly,

    m

  179. Hey TInk

    I spoke WAY too soon. I downloaded these source codes and I can’t make heads or tails of them. Do you have a more layman’s version? I don’t know what a public or private function is, and I have no idea how to apply this code to my flash movie. I don’t want to work with components, I just want to have the user click a button and download a file. Can you help me?

    Truly,

    m

  180. Mofi says:

    Hi Tink, I have an AIR Project made in Flex and I want to download some files from a server to a directory in the desktop. Is it possible to get rid of the OS dialog asking where to save each of the files and provide an automatic route?

    thanks a lot

    mofi

  181. Tink says:

    @ Mofi

    You can use URLStream to download the file, then once complete, write the file using File and FileStream. Here’s an example of how you would write a txt file, downloaded with URLStream to the users desktop

    var fileData:ByteArray = new ByteArray();
    _urlStream.readBytes( fileData, 0, _urlStream.bytesAvailable );

    var file:File = File.desktopDirectory.resolvePath(“MyFile.txt”);
    var fileStream:FileStream = new FileStream();
    fileStream.open( file, FileMode.WRITE );
    fileStream.writeBytes( fileData, 0, fileData.length );
    fileStream.close();

  182. Mofi says:

    Tink a thousand thanks to you, it worked like a charm

    Thanks again

    mofi

  183. Jan Kratochvil says:

    Tink
    Is it possible to delete my email address from this topic please?
    Via email can’t block the notification.
    Thanks Jan.

  184. Georgi says:

    Hi, I am using the script and works really cool :) . I just have one queston if it possible to change the file name. I notice a problem when uploading files with long names or containing +”" and other stranges characters.

    Wonder if anyone had a solotion to validate filename? or change?. Like in PHP you have preg_replace if or something?.

  185. Tink says:

    @ Georgi

    You can name the files what you want viw the serverside script.

    The PHP script provided here looks at the Filedata sent with the uploading file, and uses the name property found in that

    ['Filedata']['name']

    @ Jan

    I’ve been saying to for a while, but i promise to upgrade my WordPress and sort this unsubscribing issue out this week. Apologies to all who have asked this before on this post.

  186. Georgi says:

    Wow, thanks for the answer Tink :) . Fast and relly helpful.

    I have just one single queston:S. I just discovered with flash filereference that you get an error when you upload file/files with zero size (0bytes).

    Is it possible to validate before an upload, say to the user that it not good file or warn something?. Thanks Tink.

  187. Tink says:

    Once the user has selected their file the FileReference object get some read only properties set on it about the file chosen.

    creationDate : Date
    The creation date of the file on the local disk.

    creator : String
    [The Macintosh creator type of the file, which is only used in Mac OS versions prior to Mac OS X.

    extension : String
    [read-only] The filename extension.

    modificationDate : Date
    The date that the file on the local disk was last modified.

    name : String
    The name of the file on the local disk.

    size : Number
    The size of the file on the local disk in bytes.

    You can see an example here http://www.tink.ws/blog/filereference-example/

  188. dc says:

    Hi,
    I downloaded your file and I”m not sure how to work it.
    I’m trying to upload a video that the viewer can then download.
    If I open the download fla, and process out the swf, I’m then trying to browse a file and upload it. When I try to upload, I’m getting this error:
    upload process failed to start.
    Any suggestions?
    Thanks so much!

  189. Dan says:

    I posted a HowTo that explains AS3 FileReference usage: http://www.thedanosphere.com/?p=76

  190. YOU ENGLISH HOMO! Change the name of this post so SMART people won’t be tricked into coming here. Who would suffer the shame of not spending two seconds in the REAL DOCUMENTATION, which you TALENTLESS FLASH HACKS keep translating into your own blogs and presentations, to the LAUGHS of REAL programmers everywhere?

    I, a programmer a 1000 times better than you, would have liked to look at the actual source code of FileReference. I learned to use it in one second from the docs. The embarrassment the entire flash community should feel is on your shoulders.

  191. Tink says:

    Sheesh thats a bit harsh ;)

    You should leave a proper link here so you can share all the knowledge you have and we can all learn from you.

  192. Keith says:

    I can’t seem to get uploading to work properly on my production site, though it works locally. The PHP upload script works when I test it using a simple HTML upload form, but the Flex version refuses to work. Here is a link to the application with source code view enabled:

    http://skillzdesign.com/dhc/DrumHeadCreator.html

    I can provide the PHP code if necessary, though it’s minimal. Any suggestions would be greatly appreciated!

    Thanks,
    Keith

  193. Jaki says:

    WORKS PERFECT 4 ME !

  194. Luc says:

    Hello! I’ve been having a problem getting the fileReferenceList to upload one file at a time and there’s very little help elsewhere on the net. I’ve tried several different ways to get it to work. Every time I use the onComplete listener function it just dies on me. I’ve tried making a separate function to handle the files one at a time, but it doesn’t seem to recognize the listener events.

    Is there an actual .as example I could look at somewhere? I’ve been looking for weeks and have found nothing. Like one of your posts points out, the acstionscript example in Flash 8 loads all of the files at once because it uses a for-i loop, but then that conversation seemed to fade out…

    Please help…my brain hurts.

    Thanks
    Luc

  195. Cameron says:

    I am trying to modify your script to download a different file however whenever I change the .as file it does not reflect any change on the swf and I have looked for an action script on the fla but have not found one…

    Any help?

  196. Brent says:

    Anyone having issues in IE7 with fileRef.download(var1, var2)? When I click on my download button, nothing happens in Internet Explorer 7. In FireFox 2 and 3 it seems to work fine. I do declare the fileRef variable outside of the function which calls fileRef.download.

    My download button is inside a DataGrid, but, it does work in FireFox.

    Thx in advance

    Also, if you have problems with uploading large files, there are at least 3 variables in the php.ini file that affect this: post_max_size, upload_max_filesize and memory_limit

    Also, max_execution_time and max_input_time could affect the larger uploads as well.

  197. David says:

    Hi Tink-
    Great example. Thank you so much. I read through this post and couldn’t seem to get an answer to my problem. I’m using the upload example and am running into a onSecurityError : “” with error number SecuritySandboxError. Can’t seem to figure out why. I have a crossdomain.xml in place as well. Maybe I’m missing something. Any help would be appreciated.

    Thank you in kind.

    David

    PHP-

    [php][/php]

  198. Rod Martin says:

    I had a this problem when I updated to CS3. There is a bug in the Flash CS3 which is fixed by updating the flash player to version 10+

  199. Joplat says:

    Greetings,

    Could the FileRefence uploader script be used to upload or for uploads of video on a video site?

    Thanks.

    Joplat.

  200. Alex V says:

    How can I make it to open all files type, not just pictures and .swf ?

    Thank you!

Leave a Reply