Thread: filerefrence
View Single Post
  #1 (permalink)  
Old 07-24-2008, 02:23 PM
007none
 
Posts: n/a
Diggs:
Default filerefrence

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">
<mx:Script>
<![CDATA[
public var file:FileReference;

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

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(eventataEvent):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";
file.upload(request);
}


]]>
</mx:Script>
<mx:VBox>
<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"/>
</mx:VBox>
</mx:Application>



Reply With Quote
Sponsored Links