{"id":231,"date":"2008-01-04T17:02:12","date_gmt":"2008-01-04T08:02:12","guid":{"rendered":"http:\/\/hangunsworld.com\/blog\/231"},"modified":"2008-10-15T23:02:05","modified_gmt":"2008-10-15T14:02:05","slug":"saving-an-image-with-as3-and-php-2-filereference","status":"publish","type":"post","link":"http:\/\/hangunsworld.com\/blog\/231","title":{"rendered":"Saving an image with AS3 and PHP: 2. FileReference"},"content":{"rendered":"<p><embed src='http:\/\/hangunsworld.com\/blog\/wp-content\/uploads\/2008\/01\/upload.swf' width='550' height='400' \/><\/p>\n<div class=\"english\">The following code is an ActionScript 3.0 code that uploads files via FileReference.<\/div>\n<div class=\"korean\">\ub2e4\uc74c\uc740 FileReference\ub97c \uc774\uc6a9\ud558\uc5ec \ud30c\uc77c\uc744 \uc5c5\ub85c\ub4dc\ud558\ub294 \uc561\uc158\uc2a4\ud06c\ub9bd\ud2b83 \ucf54\ub4dc\uc785\ub2c8\ub2e4.<\/div>\n<div class=\"japanese\">Sorry, Japanese translation is not yet available.<\/div>\n<pre lang=\"actionscript3\" line=\"1\">var serverPath:String = \"\/\";\r\n\r\n\/\/ Creates a FileReference object.\r\nvar fr:FileReference = new FileReference();\r\nvar frFilter:FileFilter = new FileFilter(\"JPGs\", \"*.jpg\");\r\n\r\n\/\/ Adds events to the FileReference object.\r\nfr.addEventListener(Event.SELECT, fileSelected);\r\nfr.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, fileUploaded);\r\nfr.addEventListener(ProgressEvent.PROGRESS, fileProgress);\r\nfr.addEventListener(IOErrorEvent.IO_ERROR, errorOccured);\r\n\r\n\r\n\/**\r\n * Executes when a user selects a file to upload.\r\n *\/\r\nfunction fileSelected(evt:Event):void{\r\n\t\r\n\t\/\/ Checks the size of the file.\r\n\tif(fr.size > 200*1024){\r\n\t\ttrace(\"You can NOT upload an image lagerer than 200KB.\");\r\n\t}else{\r\n\t\tvar ur:URLRequest = new URLRequest();\r\n\t\tur.url = serverPath + \"test\/uploadok.php\";\r\n\t\t\r\n\t\t\/\/ Puts newName parameter, to avoid the multi-byte filename problem.\r\n\t\tvar uv:URLVariables = new URLVariables();\r\n\t\tuv.newName = \"upload.jpg\";\r\n\t\t\r\n\t\tur.data = uv;\r\n\t\t\r\n\t\t\/\/ Starts uploading.\r\n\t\tfr.upload(ur);\r\n\t}\/\/ end if else [fr.size]\r\n\t\r\n}\/\/ end fileSelected\r\n\r\n\r\n\/**\r\n * Executes when a file upload is finished.\r\n *\/\r\nfunction fileUploaded(evt:DataEvent):void{\r\n\ttrace(evt.data);\r\n}\/\/ end fileUploaded\r\n\r\n\/**\r\n * Executes while uploading a file.\r\n *\/\r\nfunction fileProgress(evt:ProgressEvent):void{\r\n\t\/\/trace(evt.bytesLoaded + \" \/ \" + evt.bytesTotal);\r\n}\/\/ end fileProgress\r\n\r\n\/**\r\n * Executes when an IO error occurs.\r\n *\/\r\nfunction errorOccured(evt:IOErrorEvent):void{\r\n\ttrace(\"IO error has occured.\");\r\n}\/\/ end errorOccured\r\n\r\n\r\n\/**\r\n * Shows the file browser when clicks on the stage.\r\n *\/\r\nstage.addEventListener(MouseEvent.MOUSE_DOWN, clicked);\r\nfunction clicked(evt:MouseEvent):void{\r\n\tfr.browse([frFilter]);\r\n}<\/pre>\n<div class=\"english\">In line 27 through 30, I assign newName parameter to an URLVariables object. This is to avoid IO error which occurs if the filename contains 2-byte characters. If you let the serverscript rename the uploaded file, this is not needed.<\/div>\n<div class=\"korean\">27-30\ubc88\uc9f8 \uc904\uc744 \ubcf4\uba74, URLVariables \uac1d\uccb4\uc5d0 newName \ud30c\ub77c\uba54\ud130\ub97c \uc124\uc815\ud588\uc2b5\ub2c8\ub2e4. \uc774\uac83\uc740 \ud30c\uc77c\uba85\uc5d0 \ud55c\uae00\uacfc \uac19\uc740 2\ubc14\uc774\ud2b8 \ubb38\uc790\uac00 \ud3ec\ud568\ub41c \uacbd\uc6b0 \uc11c\ubc84\uc5d0\uc11c \ud30c\uc77c \uc800\uc7a5\uc2dc\uc5d0 IO \uc5d0\ub7ec\uac00 \ubc1c\uc0dd\ud558\uae30 \ub54c\ubb38\uc5d0, \uc774\ub97c \ud53c\ud558\uae30 \uc704\ud574\uc11c newName\uc5d0 \ubcc4\ub3c4\uc758 \ud30c\uc77c\uba85\uc744 \uc800\uc7a5\ud55c \uac83\uc785\ub2c8\ub2e4. \ub9cc\uc57d \uc11c\ubc84\uce21\uc5d0\uc11c \ud30c\uc77c\uba85\uc744 \ubcc0\uacbd\ud558\ub3c4\ub85d \uad6c\uc131\ub418\uc5b4 \uc788\ub2e4\uba74, \uc774 \ubd80\ubd84\uc740 \ud544\uc694 \uc5c6\uc2b5\ub2c8\ub2e4.<\/div>\n<pre lang=\"actionscript3\" line=\"27\">var uv:URLVariables = new URLVariables();\r\nuv.newName = \"upload.jpg\";\r\n\r\nur.data = uv;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following code is an ActionScript 3.0 code that uploads files via FileReference. \ub2e4\uc74c\uc740 FileReference\ub97c \uc774\uc6a9\ud558\uc5ec \ud30c\uc77c\uc744 \uc5c5\ub85c\ub4dc\ud558\ub294 \uc561\uc158\uc2a4\ud06c\ub9bd\ud2b83 \ucf54\ub4dc\uc785\ub2c8\ub2e4. Sorry, Japanese translation is not yet available. var serverPath:String = &#8220;\/&#8221;; \/\/ Creates a FileReference object. var fr:FileReference = new FileReference(); var frFilter:FileFilter = new FileFilter(&#8220;JPGs&#8221;, &#8220;*.jpg&#8221;); \/\/ Adds events to the FileReference object. fr.addEventListener(Event.SELECT, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[139,60,61,62],"class_list":["post-231","post","type-post","status-publish","format-standard","hentry","category-as3","tag-actionscript-30","tag-bytearray","tag-filereference","tag-php"],"_links":{"self":[{"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/posts\/231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/comments?post=231"}],"version-history":[{"count":0,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/posts\/231\/revisions"}],"wp:attachment":[{"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/media?parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/categories?post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hangunsworld.com\/blog\/wp-json\/wp\/v2\/tags?post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}