<?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>Mukesh Chapagain&#039;s Blog &#187; file upload</title>
	<atom:link href="http://blog.chapagain.com.np/tag/file-upload/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.chapagain.com.np</link>
	<description>PHP Magento jQuery SQL Wordpress Joomla Programming &#38; Tutorial</description>
	<lastBuildDate>Tue, 07 Feb 2012 00:54:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>WordPress Fix: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s)</title>
		<link>http://blog.chapagain.com.np/wordpress-fix-open_basedir-restriction-in-effect-filetmp-is-not-within-the-allowed-paths/</link>
		<comments>http://blog.chapagain.com.np/wordpress-fix-open_basedir-restriction-in-effect-filetmp-is-not-within-the-allowed-paths/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 11:19:14 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[warning message]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=1549</guid>
		<description><![CDATA[Scenario: I am getting this warning message in my wordpress blog:- open_basedir restriction in effect. File(/tmp) is not within the allowed path(s) Solution: You should check the Uploading Files path settings in your wordpress admin. - Go to Settings -> Media - Under &#8216;Uploading Files&#8216;, see the path for &#8216;Store uploads in this folder&#8216; - [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/wordpress-mu-admin-login-problem/' rel='bookmark' title='Permanent Link: WordPress MU: Admin login problem'>WordPress MU: Admin login problem</a></li>
<li><a href='http://blog.chapagain.com.np/file-upload-in-php-simplified/' rel='bookmark' title='Permanent Link: File Upload in PHP :: Simplified'>File Upload in PHP :: Simplified</a></li>
<li><a href='http://blog.chapagain.com.np/wordpress-archive-link-not-working/' rel='bookmark' title='Permanent Link: WordPress: Archive link not working'>WordPress: Archive link not working</a></li>
<li><a href='http://blog.chapagain.com.np/wordpress-contact-form-7-quick-fix-spinning-arrow/' rel='bookmark' title='Permanent Link: WordPress Contact Form 7: Quick Fix to spinning arrow displays forever &#038; no success/error message displayed'>WordPress Contact Form 7: Quick Fix to spinning arrow displays forever &#038; no success/error message displayed</a></li>
<li><a href='http://blog.chapagain.com.np/how-to-find-php-version-and-php-ini-file-location-path/' rel='bookmark' title='Permanent Link: How to find php version and php.ini file location path?'>How to find php version and php.ini file location path?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong>Scenario:</strong></p>
<p>I am getting this warning message in my wordpress blog:-</p>
<blockquote><p>open_basedir restriction in effect. File(/tmp) is not within the allowed path(s)</p></blockquote>
<p><strong>Solution:</strong></p>
<p><span id="more-1549"></span></p>
<p>You should check the Uploading Files path settings in your wordpress admin.</p>
<p>- Go to <strong>Settings -> Media</strong><br />
- Under &#8216;<strong>Uploading Files</strong>&#8216;, see the path for &#8216;<strong>Store uploads in this folder</strong>&#8216;<br />
- The default value is &#8216;<strong>wp-content/uploads</strong>&#8216;</p>
<p>If you have custom folder then you can specify it here. Otherwise, keeping the default would fix the warning message.</p>
<p>Hope it helps. Thanks.</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=1549&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/wordpress-mu-admin-login-problem/' rel='bookmark' title='Permanent Link: WordPress MU: Admin login problem'>WordPress MU: Admin login problem</a></li>
<li><a href='http://blog.chapagain.com.np/file-upload-in-php-simplified/' rel='bookmark' title='Permanent Link: File Upload in PHP :: Simplified'>File Upload in PHP :: Simplified</a></li>
<li><a href='http://blog.chapagain.com.np/wordpress-archive-link-not-working/' rel='bookmark' title='Permanent Link: WordPress: Archive link not working'>WordPress: Archive link not working</a></li>
<li><a href='http://blog.chapagain.com.np/wordpress-contact-form-7-quick-fix-spinning-arrow/' rel='bookmark' title='Permanent Link: WordPress Contact Form 7: Quick Fix to spinning arrow displays forever &#038; no success/error message displayed'>WordPress Contact Form 7: Quick Fix to spinning arrow displays forever &#038; no success/error message displayed</a></li>
<li><a href='http://blog.chapagain.com.np/how-to-find-php-version-and-php-ini-file-location-path/' rel='bookmark' title='Permanent Link: How to find php version and php.ini file location path?'>How to find php version and php.ini file location path?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/wordpress-fix-open_basedir-restriction-in-effect-filetmp-is-not-within-the-allowed-paths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File Upload in PEAR and Smarty</title>
		<link>http://blog.chapagain.com.np/file-upload-in-pear-and-smarty/</link>
		<comments>http://blog.chapagain.com.np/file-upload-in-pear-and-smarty/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 10:07:18 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[PEAR]]></category>
		<category><![CDATA[Smarty]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=73</guid>
		<description><![CDATA[For uploading files, you need to install a package of PEAR called ‘HTTP_Upload’ along with the installation of PEAR and Smarty. HTTP_Upload is used for easy and secure managment of files submitted via HTML forms. This package provides an advanced system for managing uploads of files via HTML fields. Features include: 1) Handling of multiple [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/using-database-in-pear-and-smarty/' rel='bookmark' title='Permanent Link: Using database in PEAR and Smarty'>Using database in PEAR and Smarty</a></li>
<li><a href='http://blog.chapagain.com.np/pagination-in-pear-and-smarty/' rel='bookmark' title='Permanent Link: Pagination in PEAR and Smarty'>Pagination in PEAR and Smarty</a></li>
<li><a href='http://blog.chapagain.com.np/file-upload-in-php-simplified/' rel='bookmark' title='Permanent Link: File Upload in PHP :: Simplified'>File Upload in PHP :: Simplified</a></li>
<li><a href='http://blog.chapagain.com.np/multiple-file-upload-with-jquery-and-php/' rel='bookmark' title='Permanent Link: Multiple file upload with jQuery and php'>Multiple file upload with jQuery and php</a></li>
<li><a href='http://blog.chapagain.com.np/installing-the-smarty-template-engine/' rel='bookmark' title='Permanent Link: Installing the Smarty Template Engine'>Installing the Smarty Template Engine</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>For uploading files, you need to install a package of PEAR called ‘HTTP_Upload’ along with the installation of PEAR and <a title="Installing Smarty" href="http://blog.chapagain.com.np/index.php/2008/07/11/installing-the-smarty-template-engine/" target="_blank">Smarty</a>.</p>
<p class="MsoNormal" style="text-align: justify;">
<p><span id="more-73"></span></p>
<p class="MsoNormal" style="text-align: justify;">HTTP_Upload is used for easy and secure managment of files submitted via <acronym>HTML</acronym> forms. This package provides an advanced system for managing uploads of files via HTML<br />
<input type="file" /> fields. Features include:</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"><!--[if !supportLists]--><span>1)<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: "> </span></span><!--[endif]-->Handling of multiple file uploads at a time</p>
<p class="MsoNormal" style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"><!--[if !supportLists]--><span>2)<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: "> </span></span><!--[endif]-->Safe file copying/moving from temporary directories</p>
<p class="MsoNormal" style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"><!--[if !supportLists]--><span>3)<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: "> </span></span><!--[endif]-->Upload validaton mechanisms</p>
<p class="MsoNormal" style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"><!--[if !supportLists]--><span>4)<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: "> </span></span><!--[endif]-->Extensive information about uploaded files</p>
<p class="MsoNormal" style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"><!--[if !supportLists]--><span>5)<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: "> </span></span><!--[endif]-->Renaming uploaded files</p>
<p class="MsoNormal" style="margin-left: 0.5in; text-align: justify; text-indent: -0.25in;"><!--[if !supportLists]--><span>6)<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: "> </span></span><!--[endif]-->Internationalized error messages</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">Two class files are included in index.php. One is ConnectSmarty.class.php which is used for connecting with Smarty. I have explained about it in my <a title="Installing Smarty" href="http://blog.chapagain.com.np/index.php/2008/07/11/installing-the-smarty-template-engine/" target="_blank">previous article</a>. The other is files.class.php.</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">files.class.php</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">
<pre class="brush: php; title: ; notranslate">&lt;?php
require_once &quot;HTTP/Upload.php&quot;;&lt;/p&gt;
class Files
{
function upload($field_name,$dest)
{
$upload =&amp; new HTTP_Upload(&quot;en&quot;);
$file = $upload-&gt;getFiles($field_name);&lt;/p&gt;
if ($file-&gt;isValid())
{
$moved = $file-&gt;moveTo(&quot;$dest/&quot;);
if (PEAR::isError($moved))
{
require_once('ConnectSmarty.class.php');
// create an object of the class included above
$smarty = new ConnectSmarty;&lt;/p&gt;
$error =&amp; $moved-&gt;getMessage();&lt;/p&gt;
// assign error message
$smarty-&gt;assign('errmessage',$error);

// display error message and exit
$smarty-&gt;display('error.tpl');
exit();
}
}
}
}
?&gt;</pre>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">This class file includes the upload class which becomes available after installing the HTTP_Upload package. I have created a function named ‘upload’ inside the class ‘Files’. The <em>upload()</em> function requires two parameters: <em>$field_name</em> and <em>$dest</em>.</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;"><em>$field_name</em> is the name of input file.</p>
<p class="MsoNormal" style="text-align: justify;"><em>$dest</em> is the name of the destination directory where the file is to be uploaded.</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">The function <em>getFiles() </em>checks if a valid file was uploaded through the form. If the file is valid then it is moved to the destination directory.</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">If there is error while moving the file to the destination directory then the error message is fetched through the <em>getMessage()</em> function and displayed in a separate template file called error.tpl.</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">index.php</p>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">
<pre class="brush: php; title: ; notranslate">&lt;?php
require_once('classes/ConnectSmarty.class.php');
require_once ('classes/files.class.php');&lt;/p&gt;
// create an object of the class included above
$smarty = new ConnectSmarty;&lt;/p&gt;
if(isset($_POST['submit']))
{
$post = $_POST;
$keys = &quot;&quot;;&lt;/p&gt;
$type = $_FILES['logo']['type'];&lt;/p&gt;
// Only allowing jpeg and gif image to be uploaded
if($type == &quot;image/jpeg&quot; || $type == &quot;image/gif&quot;)
{
/**
* file upload part
* creating an object of the class Files
* calling the upload function of the class Files
* the destination directory is to be created at first
* in this case, the destination directory is created and named 'uploads'
*/
$file =&amp; new Files;
$fieldName = &quot;logo&quot;;
$dest = &quot;uploads&quot;;
$file-&gt;upload($fieldName,$dest);

// assign success message
$smarty-&gt;assign('success','File Uploaded Successfully');
}
else
{
// assign error message
$smarty-&gt;assign('error','Only jpge and gif image are supported.');

// display error message and exit
$smarty-&gt;display('index.tpl');
exit();
}
}

// display the content
$smarty-&gt;display('index.tpl');

?&gt;</pre>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">I have only allowed jpeg and gif image to be uploaded. If the file is successfully uploaded then a success message is assigned and displayed.</p>
<p class="MsoNormal" style="text-align: justify;">
<pre class="brush: php; title: ; notranslate">// assign success message

$smarty-&gt;assign('success','File Uploaded Successfully');</pre>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;">If the file is not of jpeg or gif type then an error message is assigned and displayed.</p>
<p class="MsoNormal" style="text-align: justify;">
<pre class="brush: php; title: ; notranslate">// assign error message

$smarty-&gt;assign('error','Only jpge and gif image are supported.');

// display error message and exit

$smarty-&gt;display('index.tpl');

exit();</pre>
<p>index.tpl</p>
<pre class="brush: xml; title: ; notranslate">&lt;html&gt;

&lt;head&gt;
&lt;title&gt; Homepage : File Upload&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;font color=&quot;green&quot;&gt;{$success}&lt;/font&gt;
&lt;font color=&quot;red&quot;&gt;{$error}&lt;/font&gt;

&lt;h2&gt;Upload Logo&lt;/h2&gt;
&lt;table&gt;
&lt;form action=&quot;index.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
&lt;tr&gt;&lt;td&gt;Logo&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;file&quot; name=&quot;logo&quot; &gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/form&gt;
&lt;/table&gt;

&lt;/body&gt;

&lt;/html&gt;</pre>
<p>error.tpl</p>
<pre class="brush: xml; title: ; notranslate">&lt;div align=&quot;center&quot;&gt;
&lt;font color=&quot;red&quot;&gt;
{$errmessage}
&lt;/font&gt;
&lt;/div&gt;</pre>
<p class="MsoNormal" style="text-align: justify;">
<p class="MsoNormal" style="text-align: justify;"><strong><span><a title="File upload in PEAR and Smarty" href="http://chapagain.googlecode.com/files/fileupload_pear_smarty.zip">Download source code</a></span></strong></p>
<p class="MsoNormal" style="text-align: justify;"><span> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span>Note: <em>I have not included Smarty library files in this zip file. You can download the Smarty library files from </em></span><a title="Download Smarty" href="http://smarty.php.net/download.php" target="_blank">http://smarty.php.net/download.php</a><span><em> or directly from </em></span><a href="http://chapagain.googlecode.com/files/smarty.zip">http://chapagain.googlecode.com/files/smarty.zip</a></p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=73&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/using-database-in-pear-and-smarty/' rel='bookmark' title='Permanent Link: Using database in PEAR and Smarty'>Using database in PEAR and Smarty</a></li>
<li><a href='http://blog.chapagain.com.np/pagination-in-pear-and-smarty/' rel='bookmark' title='Permanent Link: Pagination in PEAR and Smarty'>Pagination in PEAR and Smarty</a></li>
<li><a href='http://blog.chapagain.com.np/file-upload-in-php-simplified/' rel='bookmark' title='Permanent Link: File Upload in PHP :: Simplified'>File Upload in PHP :: Simplified</a></li>
<li><a href='http://blog.chapagain.com.np/multiple-file-upload-with-jquery-and-php/' rel='bookmark' title='Permanent Link: Multiple file upload with jQuery and php'>Multiple file upload with jQuery and php</a></li>
<li><a href='http://blog.chapagain.com.np/installing-the-smarty-template-engine/' rel='bookmark' title='Permanent Link: Installing the Smarty Template Engine'>Installing the Smarty Template Engine</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/file-upload-in-pear-and-smarty/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>File Upload in PHP :: Simplified</title>
		<link>http://blog.chapagain.com.np/file-upload-in-php-simplified/</link>
		<comments>http://blog.chapagain.com.np/file-upload-in-php-simplified/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 07:30:36 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[file upload]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/2007/12/07/file-upload-in-php-simplified/</guid>
		<description><![CDATA[Here is the php code for file upload (image upload in this case) with description included within the code: There are two files. &#8216;fileupload.html&#8217; contains the form to upload file and &#8216;upload.php&#8217; contains the php code. Download link for the code and tutorial of file upload: File Upload code fileupload.html upload.php Download link: File Upload code  [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/multiple-file-upload-with-jquery-and-php/' rel='bookmark' title='Permanent Link: Multiple file upload with jQuery and php'>Multiple file upload with jQuery and php</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-upload-file/' rel='bookmark' title='Permanent Link: Magento: How to upload file?'>Magento: How to upload file?</a></li>
<li><a href='http://blog.chapagain.com.np/file-upload-in-pear-and-smarty/' rel='bookmark' title='Permanent Link: File Upload in PEAR and Smarty'>File Upload in PEAR and Smarty</a></li>
<li><a href='http://blog.chapagain.com.np/how-to-find-php-version-and-php-ini-file-location-path/' rel='bookmark' title='Permanent Link: How to find php version and php.ini file location path?'>How to find php version and php.ini file location path?</a></li>
<li><a href='http://blog.chapagain.com.np/generating-random-image/' rel='bookmark' title='Permanent Link: Generating random image'>Generating random image</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here is the php code for file upload (image upload in this case) with description included within the code:</p>
<p>There are two files. &#8216;fileupload.html&#8217; contains the form to upload file and &#8216;upload.php&#8217; contains the php code.</p>
<p><span id="more-30"></span></p>
<p>Download link for the code and tutorial of file upload:</p>
<p><a href="http://blog.chapagain.com.np/wp-content/uploads/2007/12/file-upload.zip" title="File Upload code">File Upload code</a></p>
<p>fileupload.html</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
&lt;title&gt;File Upload&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form action=&quot;upload.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
&lt;p&gt;File Upload&lt;/p&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;File&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;file&quot; name=&quot;file&quot; id=&quot;file&quot; /&gt; &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>upload.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
&lt;title&gt;File Upload&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;?php
if(isset($_POST['submit']))
{
// first create a directory named 'uploads' inside your website directory
$uploadDirectory = &quot;uploads&quot;;
// this is the directory name where you want to upload your files.
//this should be inside your website folder. suppose this file named upload.php is in
//folder named 'file upload' then the directory 'uploads' should be inside the directory 'file upload'

$name = $_FILES['file']['name']; // gives the file name (like logo.jpg)
$type = $_FILES['file']['type']; // gives the file type (image/jpeg)
$size = $_FILES['file']['size']; // gives the file size in bytes (like 16091)
$tmpName = $_FILES['file']['tmp_name']; // gives the temporary directory where the file is stored immediately after upload

//echo &quot;$name , $type , $size , $tmpName &quot;;

// suppose you want to show your file size in Kb (Kilobytes) then do the following
$sizeKb = ceil($_FILES['file']['size'] / 1024);
// the ceil function will round fractions up, ceil(4.3) = 5 and ceil(9.999) = 10

//echo &quot;$sizeKb KB&quot;;

// suppose you want to allow only jpeg and gif image to be uploaded, and you also want the file size to be not more than 1MB
//i.e. your maximum file size limit is 1MB, then you need to do the following

// checking for file size and file type,
// for 1MB = (1024 * 1024 = 1048576)
// if you want to do for 500KB then (1024 * 500 = 51200)
if(($type != &quot;image/jpeg&quot; || $type != &quot;image/gif&quot;) &amp;&amp; ($size &gt; 1048576))
{
echo &quot;Only jpeg or gif image with size upto 1MB are allowed.&quot;;
}
else
{
// checking whether the file already exists in the upload folder
// $uploadDirectory and $name used here are defined above
if(file_exists(&quot;$uploadDirectory/$name&quot;))
{
// if the file exits then print the message
echo &quot;The file with the name $name already exists. Please choose another file and try again.&quot;;
}
else
{
// moving the file to uploads directory
move_uploaded_file(&quot;$tmpName&quot;,&quot;$uploadDirectory/$name&quot;);
// print the success message
echo &quot;File has been successfully uploaded.&quot;;
}
}
}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Download link:</p>
<p><a href="http://blog.chapagain.com.np/wp-content/uploads/2007/12/file-upload.zip" title="File Upload code">File Upload code</a> </p>
<p>Enjoy!</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=30&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/multiple-file-upload-with-jquery-and-php/' rel='bookmark' title='Permanent Link: Multiple file upload with jQuery and php'>Multiple file upload with jQuery and php</a></li>
<li><a href='http://blog.chapagain.com.np/magento-how-to-upload-file/' rel='bookmark' title='Permanent Link: Magento: How to upload file?'>Magento: How to upload file?</a></li>
<li><a href='http://blog.chapagain.com.np/file-upload-in-pear-and-smarty/' rel='bookmark' title='Permanent Link: File Upload in PEAR and Smarty'>File Upload in PEAR and Smarty</a></li>
<li><a href='http://blog.chapagain.com.np/how-to-find-php-version-and-php-ini-file-location-path/' rel='bookmark' title='Permanent Link: How to find php version and php.ini file location path?'>How to find php version and php.ini file location path?</a></li>
<li><a href='http://blog.chapagain.com.np/generating-random-image/' rel='bookmark' title='Permanent Link: Generating random image'>Generating random image</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/file-upload-in-php-simplified/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
