joshbuhler.com

File Upload Source Now Available

by Josh on Sep.14, 2005, under ActionScript, Flash

About a month ago I posted an example swf of the new file uploading features of Flash 8. I've had a few requests for the source files, so here they are.

Links:

One note: depending on where you put these files, you may need to adjust the url's used by the swf. You'll find them in main.as beginning on line 13.

  1. // url vars
  2. var imageFolder:String = "images/";
  3. var uploadScript:String = "fileUpload.php";


:
24 comments for this entry:
  1. Jen

    Documentation also includes source files and a tutorial for file upload with PHP.

    Check out:

    C:\Program Files\Macromedia\Flash 8\Samples and Tutorials\Samples\ActionScript\FileUpload

    And in the Help panel for PHP and the tutorial:

    Learning ActionScript 2.0 in Flash > Working with External Data > About file uploading and downloading > Adding file upload functionality to an application

  2. nate

    Hello, i’m looking through your source code and trying to get it to work and have a couple of questions.

    1. i assume you need to create the “temporary” dir on your server right?

    2. for some reason when I try to upload nothing happens. this has happened with other code examples too. I used a variable and a dyn text box to trace out your error handling but nothing shows up when I test on the server. when I test locally I can see all of the traces and don’t get any errors (but no file is uploaded)

    3. if i hit the php file i get an error;
    Warning: exif_imagetype(): Read error! in /home/virtual/site370/fst/home/sssd/public_html/fileUpload.php on line 19

    it seems like i’m running into some kind of security issue… is there anything else i’m not considering?

    thanks for your source!

  3. Emp

    Hi there,

    great Upload Example.

    Maybe you can help me with an extra feature on it.

    I’m trying to put in an email address field as well. An Input Text field with var: email

    When you push the upload button, the email address will go with it. Can you help me out with that little problem?

    Thnx in advance for your help.

  4. daniel

    im gonna test this at home heheh

  5. M!ke

    Hi there.

    Very good example.

    Unfortunaly i’m having the same problem as nate:

    Warning: exif_imagetype(): Read error!

    All was working great, until last week, when it starts to giving me that error. I tried do unlock all sort of security but i’m still getting that error.

    If someone knows whats happening i’ll be very appreciated. tanx in advance

  6. mugafuga

    Yeah this is lame I keep getting 406 errors. Everytime I used it when it fist came out it worked fine. I have a bunch file upload apps. And and they are all not working. It’s like it happened magically or something because I haven’t changed any code. This problem is driving me insane.

  7. matt

    Hello, i’m looking through your source code and trying to get it to work and have a couple of questions.

    1. i assume you need to create the “temporary” dir on your server right?

    2. for some reason when I try to upload nothing happens. this has happened with other code examples too. I used a variable and a dyn text box to trace out your error handling but nothing shows up when I test on the server. when I test locally I can see all of the traces and don’t get any errors (but no file is uploaded)

    3. if i hit the php file i get an error;
    Warning: exif_imagetype(): Read error! in /home/virtual/site370/fst/home/sssd/public_html/fileUpload.php on line 19

    it seems like i’m running into some kind of security issue… is there anything else i’m not considering?

    thanks for your source!

  8. Trenton Ahrens

    EDIT: it can also be because flash likes to double up the content boundaries. Sometimes its not neccessarly because there is mismatched types. Which I still dont understand why! Its retarted.

  9. andrei

    hello,
    i’d like to make my own web site and to put there a reply as this one. Simple, with putiing visitors name, emai, website and a short text and all to come to a speciffice mail.

    Thank you, Andrei

  10. video

    It is a execell code which i need.THANKS

  11. Mike

    I have no problem running it on my server, and everything works just fine, however, I need to know how to save the modified image (for example when I resize the uploaded image) to the same folder on the server or to save it locally if possible at all.
    would anyone please help, any comments or ideas would be greatly appreciated.

  12. Dariux

    The same error /* 1 */
    Warning: exif_imagetype(): Unable to access ./temporary/ in /home/13112/domains/joshbuhler.com/html/regresoaxelha/upload-image/fileUpload.php on line 19

    Warning: exif_imagetype(./temporary/): failed to open stream: No such file or directory in /home/13112/domains/joshbuhler.com/html/regresoaxelha/upload-image/fileUpload.php on line 19

    Warning: unlink(./temporary/): No such file or directory in /home/13112/domains/joshbuhler.com/html/regresoaxelha/upload-image/fileUpload.php on line 23
    Array ( [0] => Array ( [0] => ./images/.. [1] => 1145374186 ) [1] => Array ( [0] => ./images/. [1] => 1145374186 ) )

  13. prasanna

    thanks a lot

  14. Samc

    Hi,

    I’ve download your source code and uploaded it to my server. Adding the images folder, within the same folder as all your source files (that is the right thing to do isn’t it), and when i upload it and try it out, i hit the browse button, it lets me browse my files, but when i select my image to upload, and upload it, it doesn’t upload it, and therefore does not display in the window.

    Do you have any idea what i could have done wrong, i haven’t edited any of your code….?

  15. Kevin

    Thanks for this source code. Very well documented and very clean.

    I am having one issue with it and it appears to be Mac oriented only. When I click ‘browse’, all the files are grey in my browse window on the Mac. I’ve tested this on Windows XP and it works fine. So I’m fairly certain this is a Mac issue only. Unfortunately, we’re an all Mac office and I need to be able to use this here.

    I’ve tried eliminating the macfile information from the file type array, even tried making the file extentions be *.*, but I can’t seem to select a file to upload. I even went so far as to take out the filetype from the () for the file browse, but no luck.

    Any ideas on how to get around this?

  16. Josh

    Are you using Leopard? (OS X 10.5) The first version of 10.5 had a few bugs with uploading files in Flash that have since been fixed with updates to both OS X 10.5.1 and Flash Player 9.0.115.

  17. Kevin

    Yes, I have upgraded to 10.5.1 and Flash Player 9.0.115.

    I’ve been trying to see if I can find the issue with the code and I’ve been unable to find the problem. Your code seems perfectly sound. I have another uploader that it’s near as robust, but it works fine. His function names are different, but his scheme is pretty much the same as yours. The one difference I can point to is in the browse dialog box when it’s showing the files. In his, there is no popup menu saying ‘All Readable Files’, whereas yours does have that popup menu. What’s also odd about that popup menu is when you select it, below the ‘All Readable Files’, it just says document four (4) times. Obviously selecting those don’t help, but the ‘All Readable Files’ doesn’t work either.

    I’m truly stumped.

    I can send a screenshot if you like.

  18. Kevin

    Sorry… meant to say the other upload is NOT near as robust. ;-)

  19. kathy

    This works great thanks!

    I need to add the ability to drag the photo into position, so you can see it thru a mask…tried adding a startDrag to the
    “image” in the Main.as file. Didn’t work

  20. Thijs Triemstra

    @kevin: that’s a problem with the ‘macType’ parameter that looks like this and doesn’t make much sense..? Line 33, main.as defines:

    var fileTypes:Array = [{description: "Image files", extension: "*.jpg;*.gif;*.png", macType: "JPEG;jp2_;GIFf;PNGf"}];

    If you remove the macType property it works fine:

    var fileTypes:Array = [{description: "Image files", extension: "*.jpg;*.gif;*.png"];

  21. varun

    very nice example dude..

  22. John

    Thanks Josh, it’s 2008 and this still one of the main blogs on the issue.

    I’ll show you what I end up doing with it for a client… you’ll get a good laugh.

  23. Alex

    Hiya,

    I just wanted to say Thank You for this post, it really helped me getting to grips with uploading external files through Flash!

    Cheers,
    ALEX

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...