2 Replies Latest reply on Jul 24, 2008 11:43 PM by FlexPrashant


      Hi i am trying to upload file with php... Now this is working properly but when i select a file then click on upload it's saving the file again without selecting any file if i will again click on upload it will again save the same file ..
      I want to prevent this mean to say if a user not selecting file again file must not be uploaded again .....
      Please help me ..

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

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      public var file:FileReference;

      public function selectFile():void
      file = new FileReference();
      file.addEventListener(Event.SELECT, fileSelected);
      file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadDataComplete);
      file.addEventListener(Event.COMPLETE, uploadComplete);
      file.addEventListener(IOErrorEvent.IO_ERROR, handleError);

      public function handleError(event:IOErrorEvent):void
      status_txt.text = 'ERROR: ' + event.text + '\n';
      public function fileSelected(event:Event):void
      file = FileReference(event.target);
      file_txt.text = file.name;
      status_txt.text = 'upload file: '+ file.name + '\n';


      public function uploadDataComplete(event:DataEvent):void
      var result:XML = new XML(event.data);
      status_txt.text += 'Upload Data Complete\n'
      status_txt.text += 'RESULT: ' + result.toString() + '\n'
      status_txt.text += 'STATUS: ' + result.status + '\n';
      status_txt.text += 'MESSAGE: '+ result.message;

      public function uploadComplete(event:Event):void
      status_txt.text += 'Upload complete\n';


      private function upload():void

      var request:URLRequest = new URLRequest();
      request.url = " http://localhost/myupload.php";

      <mx:TextInput id="file_txt"/>
      <mx:Button id="select_btn" label="select" click="selectFile();"/>
      <mx:Button label="upload" click="upload();"/>
      <mx:TextArea id="status_txt" width="400" height="200"/>
        • 1. Re: filerefrence
          I would suspect that the Event.SELECT listener is begin fired even if no file is selected and that the object file_txt still contains the file name from the previous action, so it uploads that file again. try setting file_txt.text="" before assigning it file.name.
          • 2. Re: filerefrence
            FlexPrashant Level 1
            Thanks for your reply ... i Have tried your suggestion but it's not the solution ... Until and Up to i will not remove file name from file reference object ,it will again upload it ... But i don't know how to remove file name from file object ...