0 Replies Latest reply on Jun 23, 2011 11:59 AM by zach.walker@williams.com

    Need help uploading a file using Flex and PHP


      I have a PHP script that I want to use to upload a file from a Flex app.  The php code works if I call it from an HTML page and the file is uploaded propperly.  When I try to use my Flex code I get a completed event but the file is no where to be found.  Here is the Flex and PHP code im using:



      $target_path =


      $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);


      (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

      echo "The file ". basename( $_FILES['uploadedfile']['name']).

      " has been uploaded";

      } else{

      echo "There was an error uploading the file, please try again!";




      <?xml version="1.0" encoding="utf-8"?>




      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">



      public var fileRef:FileReference;


      public var filename:String;


      public var fileSize:String;

      public function init():void


      fileRef =

      new FileReference;

      fileRef.addEventListener(Event.SELECT, selectHandler);

      fileRef.addEventListener(Event.COMPLETE, completeHandler);


      public function browseHandler(e:Event):void




      public function selectHandler(e:Event):void


      uploadBtn.enabled =


      fileInfo.text = fileRef.name;

      fileSizeInfo.text = fileRef.size.toString();


      public function completeHandler(e:Event):void




      public function uploadHandler(e:Event):void


      fileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS, uploadError);

      var url:String = '';

      var request:URLRequest = new URLRequest(url);

      var params:URLVariables = new URLVariables();

      params.enctype = "multipart/form-data";

      request.method = URLRequestMethod.POST;

      request.data = params;

      request.contentType = "multipart/form-data";

      fileRef.upload(request, "Custom1");


      public function uploadError(e:Event):void


      trace ("Upload Error");





      <!-- Place non-visual elements (e.g., services, value objects) here -->


      <s:Button id="browseBtn" x="443" y="299" label="Browse" click="browseHandler(event)"/>

      <s:Button id="uploadBtn" x="443" y="328" label="Upload" enabled="false" click="uploadHandler(event)"/>

      <s:TextInput id="fileInfo" x="413" y="269" editable="false"/>

      <s:Label x="340" y="273" text="File Name:"/>

      <s:TextInput id="fileSizeInfo" x="413" y="239" editable="false"/>

      <s:Label x="349" y="243" text="File Size:"/>