3 Replies Latest reply on Jul 24, 2007 10:29 AM by SummerLongSince

    Upload File AS3

    SummerLongSince
      Can anyone point me, or share a file, to a good source for a tutorial on uploading files via flash? I'm authoring on Flash CS3, my applications uses AS 3, and on the server I'm using a php script that receives images, resizes them, and saves them.

      The php script works like a charm if I submit everything through a simple html form.

      Trouble starts when I use flash. I've spent 3 days working on tutorials, using examples online, and nothing works. I'm working on a Mac, and in both firefox and Opera things just don't work.

      Is there anything I should be aware of? Should i just give up the idea of coding this feaure in AS3 and use just the html form? For consistency I'd like to use flash all the way.
        • 1. Re: Upload File AS3
          SummerLongSince Level 1
          I must have been making a mistake before, but finally -after 2 days- the CS3 example on file upload worked.

          It works for a single file upload. However I'm finding a limitation.

          The php file I'm using does some image processing: it takes the file and resizes it, converts it to a jpg, and reduces its file size. it all works fine when I call this script from an html form. If I do it from my flash file, through the file upload, I just puts the files on the desired location but doesn't do any transformation.

          This is the expected behaviour for the PHP script when it thinks the uploaded file is not an image.

          So somewhere along the flash upload the files that my php script receives are not recognized as graphic files. What can I do so that php 'understand' them as the right format, and so do the desired transformations on them?

          Thanks so much for any hints.

          ps. i can share the code for the php transformations if anyone needs it.
          • 2. Re: Upload File AS3
            SummerLongSince Level 1
            i've kept poking files and trying to see what the php script gets on each instance (upload via html form vs flash).

            I notice this difference:
            In the raw header upload via html form the type is:

            type = image/png

            when i use flash:

            type = application/octet-stream

            I wonder if this is what makes my PHP script not recognize my file as a graphic file? if so, how can i correct this within flash?
            • 3. Re: Upload File AS3
              SummerLongSince Level 1
              well, it took me 3 days to figure a solution for this issue. If someone knows of a better approach please share.

              In PHP I assign a new type description for the uploaded file. This way the PHP processing script does treat the file as an image and performs its routines.

              this is what i did in PHP:
              quote:

              // If it is an image type has to be forced
              // this because flash sends type as: type = application/octet-stream
              // and not as: type = image/jpg for instance.


              $extension = strtolower( strrchr($_FILES['Filedata']['name'], '.') );
              if ($extension == '.jpg'){
              $_FILES['Filedata']['type']='image/jpg';
              }else if ($extension == '.jpeg'){
              $_FILES['Filedata']['type']='image/jpg';
              }else if ($extension == '.gif'){
              $_FILES['Filedata']['type']='image/gif';
              }else if ($extension == '.png'){
              $_FILES['Filedata']['type']='image/png';
              }else if ($extension == '.bmp'){
              $_FILES['Filedata']['type']='image/bmp';
              }