<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hangun's World - Blog &#187; PHP</title>
	<atom:link href="http://hangunsworld.com/blog/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://hangunsworld.com/blog</link>
	<description>about ActionScript, Flash, Web and more...</description>
	<lastBuildDate>Sun, 29 Apr 2012 14:41:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Saving an image with AS3 and PHP: 3. ByteArray</title>
		<link>http://hangunsworld.com/blog/232</link>
		<comments>http://hangunsworld.com/blog/232#comments</comments>
		<pubDate>Mon, 14 Jan 2008 02:25:03 +0000</pubDate>
		<dc:creator>Hangun's World</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[FileReference]]></category>
		<category><![CDATA[GIFEncoder]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://hangunsworld.com/blog/232</guid>
		<description><![CDATA[The following ActionScript 3 code is used to save GIF image that is encoded using GIFEncoder. I use GIFEncoder, distributed via ByteArray.org, to encode GIF files. 다음은 GIFEncoder를 이용하여 인코딩한 GIF 파일을 저장하는 액션스크립트3 코드입니다. GIF 파일을 인코딩하기 위해서, ByteArray.org에서 배포하는 GIFEncoder를 사용하였습니다. これはGIFEncoderを使用してGIFファイルを保存するActionScript3のコードです。GIFファイルをエンコードするために、ByteArray.comで配布されているGIFEncoderを使いました。 1 2 3 4 5 6 7 8 9 10 11 <a href='http://hangunsworld.com/blog/232'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><embed src='http://hangunsworld.com/blog/wp-content/uploads/2008/01/upload.swf' width='550' height='400' /></p>
<div class="english">The following ActionScript 3 code is used to save GIF image that is encoded using GIFEncoder. I use GIFEncoder, distributed via ByteArray.org, to encode GIF files.</div>
<div class="korean">다음은 GIFEncoder를 이용하여 인코딩한 GIF 파일을 저장하는 액션스크립트3 코드입니다. GIF 파일을 인코딩하기 위해서, ByteArray.org에서 배포하는 GIFEncoder를 사용하였습니다.</div>
<div class="japanese">これはGIFEncoderを使用してGIFファイルを保存するActionScript3のコードです。GIFファイルをエンコードするために、ByteArray.comで配布されているGIFEncoderを使いました。</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// Imports the GIFEndocer class by Thibault Imbert.</span>
<span style="color: #009900; font-style: italic;">// You can download it from ByteArray.org.</span>
<span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>gif<span style="color: #000066; font-weight: bold;">.</span>encoder<span style="color: #000066; font-weight: bold;">.</span>GIFEncoder<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> serverPath<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;/&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// Initializes GIFEncoder</span>
<span style="color: #6699cc; font-weight: bold;">var</span> myGIFEncoder<span style="color: #000066; font-weight: bold;">:</span>GIFEncoder = <span style="color: #0033ff; font-weight: bold;">new</span> GIFEncoder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
myGIFEncoder<span style="color: #000066; font-weight: bold;">.</span>setRepeat<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
myGIFEncoder<span style="color: #000066; font-weight: bold;">.</span>setDelay <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">300</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// Initializes an URLLoader object to upload a file stream.</span>
<span style="color: #6699cc; font-weight: bold;">var</span> ul<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
ul<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> saveDone<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> urh<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequestHeader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequestHeader</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Accept&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;image/gif&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> BOUNDARY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;---------------------------7d76d1b56035e&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Starts the gif encoding when clicks on the stage.
 */</span>
<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> generateGIF<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #339966; font-weight: bold;">function</span> generateGIF<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Starts the gif encoder.</span>
	myGIFEncoder<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Add frame.</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> bd<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span>0xFFFFFF<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	myGIFEncoder<span style="color: #000066; font-weight: bold;">.</span>addFrame<span style="color: #000000;">&#40;</span>bd<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Finishes the gif encoder.</span>
	myGIFEncoder<span style="color: #000066; font-weight: bold;">.</span>finish<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Starts the upload process.</span>
	uploadGIF<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">// end generateGIF</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Generates a file stream and upload it.
 */</span>
<span style="color: #339966; font-weight: bold;">function</span> uploadGIF<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Retrieves the file stream from the GIF Encoder.</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> myGIFStream<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span> = myGIFEncoder<span style="color: #000066; font-weight: bold;">.</span>stream<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> filename<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;test.gif&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Creates the file header.</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> formData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>  =  <span style="color: #990000;">&quot;--&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> BOUNDARY <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">'<span style="">\r</span><span style="">\n</span>Content-Disposition: form-data; name=&quot;Filedata&quot;; filename=&quot;'</span> <span style="color: #000066; font-weight: bold;">+</span> filename <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">'&quot;<span style="">\r</span><span style="">\n</span>Content-Type: application/octet-stream<span style="">\r</span><span style="">\n</span><span style="">\r</span><span style="">\n</span>'</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> formData2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;<span style="">\r</span><span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
	formData2 <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;--&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> BOUNDARY <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">'<span style="">\r</span><span style="">\n</span>Content-Disposition: form-data; name=&quot;Filedata&quot;<span style="">\r</span><span style="">\n</span><span style="">\r</span><span style="">\n</span>Submit Query<span style="">\r</span><span style="">\n</span>'</span><span style="color: #000066; font-weight: bold;">;</span>
	formData2 <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;--&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> BOUNDARY <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">'--'</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
&nbsp;
	<span style="color: #009900; font-style: italic;">// Conbines the header and the file stream.</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> dataArray<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ByteArray</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ByteArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	dataArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeMultiByte</span><span style="color: #000000;">&#40;</span>formData<span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;ascii&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> k<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> k<span style="color: #000066; font-weight: bold;">&lt;</span>myGIFStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> k<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		dataArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeByte</span><span style="color: #000000;">&#40;</span>myGIFStream<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>	
	dataArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeMultiByte</span><span style="color: #000000;">&#40;</span>formData2<span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;ascii&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Initializes an URLRequest object</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> ur<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	ur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">requestHeaders</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>urh<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	ur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">method</span> = <span style="color: #004993;">URLRequestMethod</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">POST</span><span style="color: #000066; font-weight: bold;">;</span>
	ur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentType</span> = <span style="color: #990000;">&quot;multipart/form-data; boundary=&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> BOUNDARY<span style="color: #000066; font-weight: bold;">;</span>
	ur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">url</span> = serverPath <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;test/uploadok.php&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
	ur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = dataArray<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	ul<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>ur<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">// end uploadGIF</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Executes when a file upload is finished.
 */</span>
<span style="color: #339966; font-weight: bold;">function</span> saveDone<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> str<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = evt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>str<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">// end saveDone</span></pre></td></tr></table></div>

<div class="english">Special thanks to <a href="http://eung.co.kr/">Kim Eung</a>. He devised the draft of the PHP and AS3 codes. Furthermore, he allowed me to open them to the public.</div>
<div class="korean">이 PHP와 AS3 코드의 기틀을 만들고, 이 소스를 공개하는데 흔쾌히 동의하신, <a href="http://eung.co.kr/">김응</a> 실장님에게 진심으로 감사드립니다.</div>
]]></content:encoded>
			<wfw:commentRss>http://hangunsworld.com/blog/232/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Saving an image with AS3 and PHP: 2. FileReference</title>
		<link>http://hangunsworld.com/blog/231</link>
		<comments>http://hangunsworld.com/blog/231#comments</comments>
		<pubDate>Fri, 04 Jan 2008 08:02:12 +0000</pubDate>
		<dc:creator>Hangun's World</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[FileReference]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://hangunsworld.com/blog/231</guid>
		<description><![CDATA[The following code is an ActionScript 3.0 code that uploads files via FileReference. 다음은 FileReference를 이용하여 파일을 업로드하는 액션스크립트3 코드입니다. Sorry, Japanese translation is not yet available. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 <a href='http://hangunsworld.com/blog/231'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><embed src='http://hangunsworld.com/blog/wp-content/uploads/2008/01/upload.swf' width='550' height='400' /></p>
<div class="english">The following code is an ActionScript 3.0 code that uploads files via FileReference.</div>
<div class="korean">다음은 FileReference를 이용하여 파일을 업로드하는 액션스크립트3 코드입니다.</div>
<div class="japanese">Sorry, Japanese translation is not yet available.</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> serverPath<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;/&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// Creates a FileReference object.</span>
<span style="color: #6699cc; font-weight: bold;">var</span> fr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">FileReference</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">FileReference</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> frFilter<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">FileFilter</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">FileFilter</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;JPGs&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;*.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">// Adds events to the FileReference object.</span>
fr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SELECT</span><span style="color: #000066; font-weight: bold;">,</span> fileSelected<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
fr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">DataEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">UPLOAD_COMPLETE_DATA</span><span style="color: #000066; font-weight: bold;">,</span> fileUploaded<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
fr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">ProgressEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PROGRESS</span><span style="color: #000066; font-weight: bold;">,</span> fileProgress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
fr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> errorOccured<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
&nbsp;
<span style="color: #3f5fbf;">/**
 * Executes when a user selects a file to upload.
 */</span>
<span style="color: #339966; font-weight: bold;">function</span> fileSelected<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Checks the size of the file.</span>
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>fr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">1024</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;You can NOT upload an image lagerer than 200KB.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> ur<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		ur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">url</span> = serverPath <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;test/uploadok.php&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">// Puts newName parameter, to avoid the multi-byte filename problem.</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> uv<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLVariables</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLVariables</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		uv<span style="color: #000066; font-weight: bold;">.</span>newName = <span style="color: #990000;">&quot;upload.jpg&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		ur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = uv<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">// Starts uploading.</span>
		fr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">upload</span><span style="color: #000000;">&#40;</span>ur<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">// end if else [fr.size]</span>
&nbsp;
<span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">// end fileSelected</span>
&nbsp;
&nbsp;
<span style="color: #3f5fbf;">/**
 * Executes when a file upload is finished.
 */</span>
<span style="color: #339966; font-weight: bold;">function</span> fileUploaded<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DataEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">// end fileUploaded</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Executes while uploading a file.
 */</span>
<span style="color: #339966; font-weight: bold;">function</span> fileProgress<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ProgressEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">//trace(evt.bytesLoaded + &quot; / &quot; + evt.bytesTotal);</span>
<span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">// end fileProgress</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * Executes when an IO error occurs.
 */</span>
<span style="color: #339966; font-weight: bold;">function</span> errorOccured<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;IO error has occured.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span><span style="color: #009900; font-style: italic;">// end errorOccured</span>
&nbsp;
&nbsp;
<span style="color: #3f5fbf;">/**
 * Shows the file browser when clicks on the stage.
 */</span>
<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> clicked<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #339966; font-weight: bold;">function</span> clicked<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
	fr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">browse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>frFilter<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<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>
<div class="korean">27-30번째 줄을 보면, URLVariables 객체에 newName 파라메터를 설정했습니다. 이것은 파일명에 한글과 같은 2바이트 문자가 포함된 경우 서버에서 파일 저장시에 IO 에러가 발생하기 때문에, 이를 피하기 위해서 newName에 별도의 파일명을 저장한 것입니다. 만약 서버측에서 파일명을 변경하도록 구성되어 있다면, 이 부분은 필요 없습니다.</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>27
28
29
30
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> uv<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLVariables</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLVariables</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
uv<span style="color: #000066; font-weight: bold;">.</span>newName = <span style="color: #990000;">&quot;upload.jpg&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
ur<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = uv<span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://hangunsworld.com/blog/231/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Saving an image with AS3 and PHP: 1. PHP</title>
		<link>http://hangunsworld.com/blog/230</link>
		<comments>http://hangunsworld.com/blog/230#comments</comments>
		<pubDate>Fri, 04 Jan 2008 05:16:59 +0000</pubDate>
		<dc:creator>Hangun's World</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[ServerScript]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[FileReference]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://hangunsworld.com/blog/230</guid>
		<description><![CDATA[The following PHP code is the code to save an image, which is uploaded using FileReference or is encoded using ByteArray in a Flash movie. The uploadok.php file can handle all the files, uploaded using FileReference, ByteArray or a file form in an HTML document. 다음 코드는 플래시에서 FileReference를 사용한 업로드 또는 ByteArray로 인코딩된 파일을 <a href='http://hangunsworld.com/blog/230'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><embed src='http://hangunsworld.com/blog/wp-content/uploads/2008/01/upload.swf' width='550' height='400' /></p>
<div class="english">The following PHP code is the code to save an image, which is uploaded using FileReference or is encoded using ByteArray in a Flash movie. The uploadok.php file can handle all the files, uploaded using FileReference, ByteArray or a file form in an HTML document.</div>
<div class="korean">다음 코드는 플래시에서 FileReference를 사용한 업로드 또는 ByteArray로 인코딩된 파일을 저장하기 위한 PHP 코드입니다. 이 uploadok.php 파일 하나로 플래시의 FileReference, ByteArray는 물론 HTML문서의 파일 양식을 통한 업로드도 모두 처리가 가능합니다.</div>
<div class="japanese">Sorry, Japanese translation is not yet available.</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #009933; font-style: italic;">/**
 * uploadok.php
 * ------------
 * Author: Han Sanghun (http://hangunsworld.com, hanguns@gmail.com)
 *       Kim Eung (http://eung.co.kr/)
 * Release Version: 1.0.0
 * Date Started: 2007/04/01
 * Last Modified: 2008/01/04
 *
 * Determines the name of the saved file.
 * If &quot;newName&quot; is provided, then uses &quot;newName&quot; as the file's name.
 * Otherwise, uses the original filename(&quot;Filedata.name&quot;) as the filename.
 *
 * If the original name of the file contains 2-byte characters (e.g. Korean characters), IO error occurs.
 * To avoid this, use &quot;newName&quot; parameter defined in Flash, rather than the &quot;Filedata.name&quot;.
 * It is possible to assigns a new name in PHP code explicitly.
 */</span>
&nbsp;
<span style="color: #000088;">$newName</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;newName&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newName</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// If newName is not defined, uses Filedata.name as the filename.</span>
	<span style="color: #000088;">$newName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$HTTP_POST_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Filedata'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Creates &quot;images&quot; folder, if not exist.</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;./images&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;./images&quot;</span><span style="color: #339933;">,</span><span style="color: #208080;">0777</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sets the path in which the uploaded image to be stored.</span>
<span style="color: #000088;">$folderPath</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/test/images/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$newPath</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$folderPath</span><span style="color: #339933;">.</span><span style="color: #000088;">$newName</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Moves the temporary file.</span>
<span style="color: #339933;">@</span><span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$HTTP_POST_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Filedata'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newPath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Returns the saved file path.</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;/test/images/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$newName</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<div class="english">Special thanks to <a href="http://eung.co.kr/">Kim Eung</a>. He devised the draft of the PHP and AS3 codes. Furthermore, he allowed me to open them to the public.</div>
<div class="korean">이 PHP와 AS3 코드의 기틀을 만들고, 이 소스를 공개하는데 흔쾌히 동의하신, <a href="http://eung.co.kr/">김응</a> 실장님에게 진심으로 감사드립니다.</div>
]]></content:encoded>
			<wfw:commentRss>http://hangunsworld.com/blog/230/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

