Pay for Hesitation: Upload File in Flex
Pay for Hesitation
Ideas are Worthless Unless Acted Upon
Pages
Home
Authors
2007年12月8日 星期六
Upload File in Flex
Demo:
http://140.112.31.185/flex/DBtest/bin/fileupload.html
upload.php
<br /><?php<br /> // you send messages back to the client<br /> // and then move the file from php's temporary upload directory to your local directory<br /> // Filedata is the default name used in uploading<br /> echo "\nReceiving upload...\n";<br /> echo "temporary file name = " . $_FILES['Filedata']['tmp_name']."\n";<br /> echo "file name = " . $_FILES['Filedata']['name']."\n";<br /> echo "file size = " . $_FILES['Filedata']['size']."\n";<br /> echo "attempting to move file...\n";<br /> move_uploaded_file($_FILES['Filedata']['tmp_name'], "./".$_FILES['Filedata']['name']);<br /> echo "file moved\n";<br />?><br />
fileupload.mxml
<br /><?xml version="1.0" encoding="utf-8"?><br /><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#f6f6f6" backgroundGradientColors="[#f6f6f6, #bbbbbb]"><br /><br /> <mx:Label x="10" y="10" text="File Upload" fontSize="20" fontWeight="bold"/><br /> <mx:HRule x="10" y="49" width="80%"/><br /> <br /> <mx:Button x="10" y="59" label="Upload" click="{upload()}"/><br /> <br /> <mx:Script><br /> <![CDATA[<br /> import flash.events.DataEvent;<br /> <br /> public var fileRef:FileReference = new FileReference();<br /> <br /> public function upload():void {<br /><br /> fileRef.addEventListener(Event.SELECT, selectHandler);<br /> fileRef.addEventListener(Event.COMPLETE, completeHandler);<br /> fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA , uploadCompleteHandler);<br /> <br /> try {<br /> var success:Boolean = fileRef.browse();<br /> }<br /> catch (error:Error) {<br /> trace("Unable to browse for files.");<br /> }<br /> }<br /> <br /> public function selectHandler(event:Event):void {<br /> var request:URLRequest = new URLRequest("http://140.112.31.185/flex/php/upload.php");<br /> try {<br /> fileRef.upload(request);<br /> textarea1.text = "uploading " + fileRef.name + "...";<br /> }<br /> catch (error:Error) {<br /> trace("Unable to upload file.");<br /> }<br /> }<br /> <br /> public function completeHandler(event:Event):void {<br /> trace("file uploaded complete");<br /> }<br /> <br /> public function uploadCompleteHandler(event:DataEvent):void {<br /> trace("uploaded... response from server: \n" + String(event.data));<br /> textarea1.text += event.data as String;<br /> }<br /> <br /> ]]><br /> </mx:Script><br /> <br /> <mx:TextArea x="10" y="89" width="327" height="134" id="textarea1"/><br /><br /></mx:Application><br />
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言