<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Ralph Whitbeck - Blog - PHP</title>
    <link>http://ralphwhitbeck.com/</link>
    <description />
    <language>en-us</language>
    <copyright>Ralph Whitbeck</copyright>
    <lastBuildDate>Tue, 04 Aug 2009 23:51:42 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>ralph.whitbeck@gmail.com</managingEditor>
    <webMaster>ralph.whitbeck@gmail.com</webMaster>
    <item>
      <trackback:ping>http://ralphwhitbeck.com/Trackback.aspx?guid=b23c5ac4-f1d8-4e29-a94c-84c7c5c6f20d</trackback:ping>
      <pingback:server>http://ralphwhitbeck.com/pingback.aspx</pingback:server>
      <pingback:target>http://ralphwhitbeck.com/PermaLink,guid,b23c5ac4-f1d8-4e29-a94c-84c7c5c6f20d.aspx</pingback:target>
      <dc:creator>Ralph Whitbeck</dc:creator>
      <wfw:comment>http://ralphwhitbeck.com/CommentView,guid,b23c5ac4-f1d8-4e29-a94c-84c7c5c6f20d.aspx</wfw:comment>
      <wfw:commentRss>http://ralphwhitbeck.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b23c5ac4-f1d8-4e29-a94c-84c7c5c6f20d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <i>I am doing some freelance work with
PHP and I am posting these for my future reference.  This is basic PHP 101 stuff
here.</i>
        <br />
        <br />
The HTML Form:<br /><br /><code class="html"> &lt;form enctype="multipart/form-data" action="upload.php" method="post"&gt;
    Please upload your file:     &lt;div&gt;        
&lt;input id="fileUpload" name="fileUpload" type="file"&gt;        
&lt;input id="submit" name="submit" value="Submit" type="submit"&gt;    
&lt;/div&gt; &lt;/form&gt;</code><br /><br />
The key part to the form is enctype="multipart/form-data" which tells the server to
expect a file on postback.  
<br /><br />
The upload php file to process the file: 
<br /><br /><code class="php"> &lt;?php     $target_path = "uploads/";<br />
    $target_path = $target_path . basename( $_FILES['fileUpload']['name']);
    if (isset($_FILES['fileUpload']))     {        
if(move_uploaded_file($_FILES['fileUpload']['tmp_name'], $target_path)) {            
echo "The file ".  basename( $_FILES['fileUpload']['name']).            
" has been uploaded";              
} else {                  
echo "There was an error uploading the file, please try again!";              
}         } ?&gt;</code><br /><br />
First we test to see if fileUpload has a value if so it attempts to save the file
to the target path.  If all goes well we get a message that the upload passed. 
If not a message that there was a problem.<br /><p></p><img width="0" height="0" src="http://ralphwhitbeck.com/aggbug.ashx?id=b23c5ac4-f1d8-4e29-a94c-84c7c5c6f20d" /></body>
      <title>PHP 101: Uploading a file</title>
      <guid isPermaLink="false">http://ralphwhitbeck.com/PermaLink,guid,b23c5ac4-f1d8-4e29-a94c-84c7c5c6f20d.aspx</guid>
      <link>http://ralphwhitbeck.com/2009/08/04/PHP101UploadingAFile.aspx</link>
      <pubDate>Tue, 04 Aug 2009 23:51:42 GMT</pubDate>
      <description>&lt;i&gt;I am doing some freelance work with PHP and I am posting these for my future reference.&amp;nbsp;
This is basic PHP 101 stuff here.&lt;/i&gt;
&lt;br&gt;
&lt;br&gt;
The HTML Form:&lt;br&gt;
&lt;br&gt;
&lt;code class="html"&gt; &amp;lt;form enctype="multipart/form-data" action="upload.php" method="post"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Please upload your file: &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;div&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;input id="fileUpload" name="fileUpload" type="file"&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;input id="submit" name="submit" value="Submit" type="submit"&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;/div&amp;gt; &amp;lt;/form&amp;gt;&lt;/code&gt;
&lt;br&gt;
&lt;br&gt;
The key part to the form is enctype="multipart/form-data" which tells the server to
expect a file on postback.&amp;nbsp; 
&lt;br&gt;
&lt;br&gt;
The upload php file to process the file: 
&lt;br&gt;
&lt;br&gt;
&lt;code class="php"&gt; &amp;lt;?php &amp;nbsp;&amp;nbsp;&amp;nbsp; $target_path = "uploads/";&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $target_path = $target_path . basename( $_FILES['fileUpload']['name']);
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (isset($_FILES['fileUpload'])) &amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if(move_uploaded_file($_FILES['fileUpload']['tmp_name'], $target_path)) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
echo "The file ".&amp;nbsp; basename( $_FILES['fileUpload']['name']). &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
" has been uploaded"; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
} else { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
echo "There was an error uploading the file, please try again!"; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
} &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } ?&amp;gt;&lt;/code&gt;
&lt;br&gt;
&lt;br&gt;
First we test to see if fileUpload has a value if so it attempts to save the file
to the target path.&amp;nbsp; If all goes well we get a message that the upload passed.&amp;nbsp;
If not a message that there was a problem.&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://ralphwhitbeck.com/aggbug.ashx?id=b23c5ac4-f1d8-4e29-a94c-84c7c5c6f20d" /&gt;</description>
      <comments>http://ralphwhitbeck.com/CommentView,guid,b23c5ac4-f1d8-4e29-a94c-84c7c5c6f20d.aspx</comments>
      <category>How-to;PHP;Programming</category>
    </item>
  </channel>
</rss>