<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
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:series="http://unfoldingneurons.com/"
> <channel><title>Comments on: Basic File Uploading Using&#160;PHP</title> <atom:link href="http://davidwalsh.name/basic-file-uploading-php/feed" rel="self" type="application/rss+xml" /><link>http://davidwalsh.name/basic-file-uploading-php</link> <description>Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</description> <lastBuildDate>Tue, 22 May 2012 05:31:04 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: hjhgjhgj</title><link>http://davidwalsh.name/basic-file-uploading-php#comment-27664</link> <dc:creator>hjhgjhgj</dc:creator> <pubDate>Fri, 18 Nov 2011 14:38:32 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=242#comment-27664</guid> <description>//if they DID upload a file...
if($_FILES[&#039;photo&#039;][&#039;name&#039;])
{
//if no errors...
if(!$_FILES[&#039;photo&#039;][&#039;error&#039;])
{
//now is the time to modify the future file name and validate the file
$new_file_name = strtolower($_FILES[&#039;photo&#039;][&#039;tmp_name&#039;]); //rename file
if($_FILES[&#039;photo&#039;][&#039;size&#039;] &gt; (1024000)) //can&#039;t be larger than 1 MB
{
$valid_file = false;
$message = &#039;Oops!  Your file\&#039;s size is to large.&#039;;
}
//if the file has passed the test
if($valid_file)
{
//move it to where we want it to be
move_uploaded_file($_FILES[&#039;photo&#039;][&#039;tmp_name&#039;], &#039;uploads/&#039;.$new_file_name);
$message = &#039;Congratulations!  Your file was accepted.&#039;;
}
}
//if there is an error...
else
{
//set that to be the returned message
$message = &#039;Ooops!  Your upload triggered the following error:  &#039;.$_FILES[&#039;photo&#039;][&#039;error&#039;];
}
}//you get the following information for each file:
$_FILES[&#039;field_name&#039;][&#039;name&#039;]
$_FILES[&#039;field_name&#039;][&#039;size&#039;]
$_FILES[&#039;field_name&#039;][&#039;type&#039;]
$_FILES[&#039;field_name&#039;][&#039;tmp_name&#039;]</description> <content:encoded><![CDATA[<p>//if they DID upload a file&#8230;<br
/> if($_FILES['photo']['name'])<br
/> {<br
/> //if no errors&#8230;<br
/> if(!$_FILES['photo']['error'])<br
/> {<br
/> //now is the time to modify the future file name and validate the file<br
/> $new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file<br
/> if($_FILES['photo']['size'] &gt; (1024000)) //can&#8217;t be larger than 1 MB<br
/> {<br
/> $valid_file = false;<br
/> $message = &#8216;Oops!  Your file\&#8217;s size is to large.&#8217;;<br
/> }</p><p> //if the file has passed the test<br
/> if($valid_file)<br
/> {<br
/> //move it to where we want it to be<br
/> move_uploaded_file($_FILES['photo']['tmp_name'], &#8216;uploads/&#8217;.$new_file_name);<br
/> $message = &#8216;Congratulations!  Your file was accepted.&#8217;;<br
/> }<br
/> }<br
/> //if there is an error&#8230;<br
/> else<br
/> {<br
/> //set that to be the returned message<br
/> $message = &#8216;Ooops!  Your upload triggered the following error:  &#8216;.$_FILES['photo']['error'];<br
/> }<br
/> }</p><p>//you get the following information for each file:<br
/> $_FILES['field_name']['name']<br
/> $_FILES['field_name']['size']<br
/> $_FILES['field_name']['type']<br
/> $_FILES['field_name']['tmp_name']</p> ]]></content:encoded> </item> <item><title>By: Dave Thomas</title><link>http://davidwalsh.name/basic-file-uploading-php#comment-3485</link> <dc:creator>Dave Thomas</dc:creator> <pubDate>Sun, 19 Oct 2008 23:11:11 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=242#comment-3485</guid> <description>Greetings!I&#039;m a big admirer of your site David, you always get the important code or meaning across without distracting filler. It&#039;s great :)A couple of points regarding the above PHP upload script:i) $valid&#095;file is never declared true, so I added the following just before the &#039;if($valid&#095;file)&#039;.else { $valid&#095;file = true; }ii) I was unable to get it working with &#039;strtolower&#039; and the &#039;uploads/&#039; directory but this worked for me:$currentdir = getcwd();
$target = $currentdir .&#039;/uploads/&#039; . basename($&#095;FILES[&#039;photo&#039;][&#039;name&#039;]);
move&#095;uploaded&#095;file($&#095;FILES[&#039;photo&#039;][&#039;tmp&#095;name&#039;], $target);Thanks again, have fun :D</description> <content:encoded><![CDATA[<p>Greetings!</p><p>I&#8217;m a big admirer of your site David, you always get the important code or meaning across without distracting filler. It&#8217;s great :)</p><p>A couple of points regarding the above PHP upload script:</p><p>i) $valid&#95;file is never declared true, so I added the following just before the &#8216;if($valid&#95;file)&#8217;.</p><p>else { $valid&#95;file = true; }</p><p>ii) I was unable to get it working with &#8216;strtolower&#8217; and the &#8216;uploads/&#8217; directory but this worked for me:</p><p>$currentdir = getcwd();<br
/> $target = $currentdir .&#8217;/uploads/&#8217; . basename($&#95;FILES['photo']['name']);<br
/> move&#95;uploaded&#95;file($&#95;FILES['photo']['tmp&#95;name'], $target);</p><p>Thanks again, have fun :D</p> ]]></content:encoded> </item> <item><title>By: david</title><link>http://davidwalsh.name/basic-file-uploading-php#comment-967</link> <dc:creator>david</dc:creator> <pubDate>Fri, 02 May 2008 19:56:34 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=242#comment-967</guid> <description>@Binny:  Great work!</description> <content:encoded><![CDATA[<p>@Binny:  Great work!</p> ]]></content:encoded> </item> <item><title>By: Binny V A</title><link>http://davidwalsh.name/basic-file-uploading-php#comment-966</link> <dc:creator>Binny V A</dc:creator> <pubDate>Fri, 02 May 2008 19:38:41 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=242#comment-966</guid> <description>I have written a function that makes this process much easier. For those interested, &lt;a href=&quot;http://www.bin-co.com/php/scripts/upload_function/&quot; rel=&quot;nofollow&quot;&gt;upload()&lt;/a&gt;.</description> <content:encoded><![CDATA[<p>I have written a function that makes this process much easier. For those interested, <a
href="http://www.bin-co.com/php/scripts/upload_function/" rel="nofollow">upload()</a>.</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 3/7 queries in 0.012 seconds using disk: basic
Object Caching 451/451 objects using disk: basic

Served from: davidwalsh.name @ 2012-05-22 01:53:09 -->
