<?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"
	>

<channel>
	<title>Codeplague &#187; PHP</title>
	<atom:link href="http://blog.codeplague.org/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codeplague.org</link>
	<description>When coding becomes the plague</description>
	<pubDate>Mon, 14 Apr 2008 04:02:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Upload XML into Flex</title>
		<link>http://blog.codeplague.org/2008/01/10/upload-xml-into-flex/</link>
		<comments>http://blog.codeplague.org/2008/01/10/upload-xml-into-flex/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 03:31:50 +0000</pubDate>
		<dc:creator>wesw02</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Flex Upload]]></category>

		<guid isPermaLink="false">http://blog.codeplague.org/2008/01/10/upload-xml-into-flex/</guid>
		<description><![CDATA[Today I was asked to add some functionality to a flex application I have been developing, that functionality was to give users the option to upload the XML data file, rather than fetch it from the server. I won&#8217;t go in to the details of the application, just that it is completely driven on its [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was asked to add some functionality to a flex application I have been developing, that functionality was to give users the option to upload the XML data file, rather than fetch it from the server. I won&#8217;t go in to the details of the application, just that it is completely driven on its data, which is provided via XML. After doing some reading I was surprised to learn that it is not possible to upload an XML file without a server side script of some kind. I choose to use PHP because its quick, easy, and simple. So the concept is that the user sends the file through flex to a server side script, that script accepts the file and returns its contents back to flex as XML.</p>
<p>Here is the flex code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript">&lt;mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
  layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;275&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;354&quot;</span> 
  creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span>&gt;
&lt;mx:Script&gt;
&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
  <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">*</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">*</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">FileReference</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">FileFilter</span>;
&nbsp;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> myXML:<span style="color: #0066CC;">XML</span>;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> file:FileReference;
&nbsp;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    file = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">// Add Event Listners</span>
    file.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">SELECT</span>, userSelectedFile<span style="color: #66cc66;">&#41;</span>;
    file.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>DataEvent.<span style="color: #006600;">UPLOAD_COMPLETE_DATA</span>, serverResponse<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> browse<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    file.<span style="color: #006600;">browse</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #000000; font-weight: bold;">new</span> FileFilter<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;XML&quot;</span>, <span style="color: #ff0000;">&quot;*.XML;&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">// Called after the user selects the file to upload</span>
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> userSelectedFile<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    file = FileReference<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
    file.<span style="color: #006600;">upload</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;file_upload.php&quot;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;FileData&quot;</span>, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">// Called after flex receives response from PHP</span>
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> serverResponse<span style="color: #66cc66;">&#40;</span>event:DataEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    myXML = <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span> event.<span style="color: #0066CC;">data</span> <span style="color: #66cc66;">&#41;</span>;
    XML_Box.<span style="color: #0066CC;">data</span> = myXML;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>&gt;
&lt;/mx:Script&gt;
&lt;mx:VBox&gt;
&lt;/mx:VBox&gt;
  &lt;mx:<span style="color: #0066CC;">Button</span> id=<span style="color: #ff0000;">&quot;Upload&quot;</span> label=<span style="color: #ff0000;">&quot;Upload&quot;</span> click=<span style="color: #ff0000;">&quot;browse()&quot;</span> x=<span style="color: #ff0000;">&quot;200&quot;</span> y=<span style="color: #ff0000;">&quot;322&quot;</span>/&gt;
  &lt;mx:TextArea id=<span style="color: #ff0000;">&quot;XML_Box&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;300&quot;</span> x=<span style="color: #ff0000;">&quot;12.5&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span>/&gt;
&lt;/mx:Application&gt;</pre></div></div>

<p>Here is the php code:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">// Set the header information</span>
<span style="color: #000066;">header</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;content-type: text/xml&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Open the uploaded file</span>
<span style="color: #0000ff;">$file_handler</span> = <span style="color: #000066;">fopen</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;FileData&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;tmp_name&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// Display the file contents</span>
<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #000066;">feof</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file_handler</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066;">echo</span> <span style="color: #000066;">fgets</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file_handler</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// Close the file</span>
<span style="color: #000066;">fclose</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file_handler</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>That&#8217;s all there is to it! To try it out just click the upload button and select an XML file to upload. If you don&#8217;t have an XML file handy you can use this <a href="http://blog.codeplague.org/content/XML_Upload/sample.xml">sample file</a>.<br />

<object type="application/x-shockwave-flash" data="http://blog.codeplague.org/content/XML_Upload/flex-app.swf" width="275" height="354">
	<param name="movie" value="http://blog.codeplague.org/content/XML_Upload/flex-app.swf" />
	<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Get FlashPlayer</a>
</object>
</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeplague.org/2008/01/10/upload-xml-into-flex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://blog.codeplague.org/2007/12/21/hello-world/</link>
		<comments>http://blog.codeplague.org/2007/12/21/hello-world/#comments</comments>
		<pubDate>Fri, 21 Dec 2007 22:56:35 +0000</pubDate>
		<dc:creator>wesw02</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.codeplague.com/?p=1</guid>
		<description><![CDATA[
&#60;script type=&#34;text/javascript&#34;&#62;
  alert&#40;'Hello World!'&#41;;
&#60;/script&#62;


&#60;?php
  echo &#34;Hello World!&#34;;
?&#62;


public class HelloWorld &#123;
  public static void main&#40;String&#91;&#93; args&#41; &#123;
    System.out.println&#40;&#34;Hello World!&#34;&#41;;
  &#125;
&#125;


#include &#60;iostream&#62;
&#160;
int main&#40;&#41;
&#123;
  std::cout &#60;&#60; &#34;Hello World!&#34; &#60;&#60; std::endl;
  return 0;
&#125;

You get the idea.
]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="javascript">&lt;script type=<span style="color: #3366CC;">&quot;text/javascript&quot;</span>&gt;
  <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Hello World!'</span><span style="color: #66cc66;">&#41;</span>;
&lt;/script&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #000066;">echo</span> <span style="color: #ff0000;">&quot;Hello World!&quot;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloWorld <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Hello World!&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="cpp"><span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  std::<span style="color: #0000dd;">cout</span> &lt;&lt; <span style="color: #666666;">&quot;Hello World!&quot;</span> &lt;&lt; std::<span style="color: #00eeff;">endl</span>;
  <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You get the idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeplague.org/2007/12/21/hello-world/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
