1 Reply Latest reply on Jul 11, 2008 6:48 AM by camfieldaj

    upload a photo flex

      How can i upload a photo using flex and display it in text area
      i tried this code plz help!!!

      upload.mxml browses the file from local system sends it to upload.php which stores it in local host . now i want to display the image in the text area of upload.mxml
      but i donot know wat to give in "imgsrc= "of text area to insert the latest image uploaded in loaclhost by upload.php

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init();">

      private var urlRequest:URLRequest;
      private var fileReferenceList:FileReferenceList;
      private var serverSideScript:String = " http://localhost/upload.php";

      private function init():void {
      urlRequest = new URLRequest(serverSideScript);
      fileReferenceList = new FileReferenceList();
      fileReferenceList.addEventListener(Event.SELECT, fileSelectedHandler);

      private function uploadFile():void {

      private function fileSelectedHandler(event:Event):void {
      var fileReference:FileReference;
      var fileReferenceList:FileReferenceList = FileReferenceList(event.target);
      var fileList:Array = fileReferenceList.fileList;

      // get the first file that the user chose
      fileReference = FileReference(fileList[0]);

      // upload the file to the server side script
      fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);

      // update the status text
      statusText.text = "Uploading...";

      private function uploadCompleteHandler(event:Event):void {
      statusText.text = "File Uploaded: " + event.target.name;
      var file:FileReference = FileReference(event.target.name);
      outputTextArea.htmlText = "<img src='http:\\localhost\\" + (file.name) + "'/>";


      <mx:Label text="Upload File From Flex to PHP" fontWeight="bold"/>
      <mx:Label text="Choose a file..." id="statusText"/>
      <mx:Button click="uploadFile();" label="Upload File"/>
      <mx:TextArea height="149" id="outputTextArea"/>



      $tempFile = $_FILES['Filedata']['tmp_name'];
      $fileName = $_FILES['Filedata']['name'];
      $fileSize = $_FILES['Filedata']['size'];

      $fp = fopen("test.txt","a+");

      move_uploaded_file($tempFile, "./" . $fileName);