1 Reply Latest reply on Jul 19, 2009 2:32 AM by jdesko

    FileReference upload to PHP some event handlers not working

    jdesko Level 2

      If you are having a problem using File Reference to upload a file to a server side PHP script and certain event listeners are not working ....


      I thought that I would post a solution to a problem that cost countless hours of code rewrites and research (or otherwise put "I could have been at the beach") in case this helps someone else.


      Using Flash Builder and server side PHP,  I have a module that allows a user to upload a file to the server.  This was a simple File Reference upload; everything was working, except event listeners for PROGESS, COMPLETE and UPLOAD_COMPLETE_DATA.  No errors were returned and the file was being uploaded successfully.  So it seemed like PHP wasn't returning something to Flash, with progress I've seen issues with small files not triggering the event handler, so this could be a separate problem.  I went through every example I could find looking for that little oversight, there is even an old 2007 article on Flex Cookbook with  MXML and PHP scripts.  Anyways, after luckily finding a blog post comment the problem seems to be with MAC's and Flash Player not the browser, both Safari and FireFox had problems, and this seems to be an old issue;  the solution is to put at the end of the PHP script


      echo " "

      (a space between the " 's).   


      Hopefully someone finds this useful.

        • 1. Re: FileReference upload to PHP some event handlers not working
          jdesko Level 2

          As a follow up to the original post. If a small file doesn't trigger the PROGRESS event handler, try a large one. 


          At the end of your php file like I mentioned you can put - echo " " - to trigger the events, but you can echo anything from your php script to  UPLOAD_COMPLETE_DATA to display it in Flex, ex. in php you can change the name of the file that you are uploading, at the end of the php script put - echo $filename - to have UPLOAD_COMPLETE_DATA display the filename.