<?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>Php Development &#187; upload</title>
	<atom:link href="http://www.maheshchari.com/tag/upload/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maheshchari.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 23 May 2010 05:10:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Upload Image File To Remote Server With PHP cURL</title>
		<link>http://www.maheshchari.com/upload-image-file-to-remote-server-with-php-curl/</link>
		<comments>http://www.maheshchari.com/upload-image-file-to-remote-server-with-php-curl/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 23:40:55 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=538</guid>
		<description><![CDATA[How to upload image file to remote server with PHP cURL
In this example we learn how to upload static files to remote server using PHP cURL library.
We must know following functionality before we continue this example

PHP file upload functionality.
cURL function reference.
how to submit data to remote server with PHP cURL

Files and Folders
Download Example
For this example [...]]]></description>
			<content:encoded><![CDATA[<h1>How to upload image file to remote server with PHP cURL</h1>
<p>In this example we learn how to upload static files to remote server using PHP cURL library.</p>
<h3>We must know following functionality before we continue this example</h3>
<ul>
<li><a href="http://www.maheshchari.com/simple-php-file-upload-tutorial/" target="_blank">PHP file upload functionality.</a></li>
<li><a href="http://www.maheshchari.com/php-curl-basic-reference/">cURL function reference.</a></li>
<li><a href="http://www.maheshchari.com/submitting-form-to-remote-server-with-array-of-parameters/" target="_blank">how to submit data to remote server with PHP cURL</a></li>
</ul>
<h3>Files and Folders</h3>
<h3><a href='http://www.maheshchari.com/wp-content/uploads/2010/03/curl_image.zip'>Download Example</a></h3>
<p>For this example we use three files </p>
<ul>
<li><strong>uploader.php</strong> -that receives the files on to the remote server.</li>
<li><strong>handler.php</strong> -is used to web based client to upload the file.</li>
<li><strong>curl_handler.php</strong> -PHP cURL uploading client to upload file.</li>
</ul>
<p>Since we use same host to both local and remote server ,we create separate directories</p>
<ul>
<li><strong>local_files/ </strong>- these files will be uploaded to the remote server ,means to <strong>uploaded_files</strong> directory.</li>
<li><strong>uploaded_files/</strong> &#8211; these files are from the uploading client from both <strong>web based </strong>and <strong>PHP cURL based</strong>.</li>
</ul>
<h3>uploader.php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$upload_directory</span><span style="color: #339933;">=</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/uploaded_files/'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//check if form submitted</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'upload'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #666666; font-style: italic;">//check for image submitted</span>
    		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #666666; font-style: italic;">// check for error re file</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Error: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;my_file&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//move temp file to our server            </span>
			<span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_file'</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;">$upload_directory</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_file'</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: #009900;">&#41;</span><span style="color: #339933;">;</span>	
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Uploaded File.'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'File not uploaded.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			<span style="color: #666666; font-style: italic;">// exit script</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>handler.php</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&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=utf-8&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;uploader.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; name=&quot;form1&quot; id=&quot;form1&quot;&gt;
  &lt;input type=&quot;file&quot; name=&quot;my_file&quot; id=&quot;my_file&quot; /&gt;
  &lt;input type=&quot;submit&quot; name=&quot;upload&quot; id=&quot;upload&quot; value=&quot;Upload&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<h3>curl_handler.php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$local_directory</span><span style="color: #339933;">=</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/local_files/'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_VERBOSE<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Mozilla/4.0 (compatible;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://localhost/curl_image/uploader.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//most importent curl assues @filed as file field</span>
    <span style="color: #000088;">$post_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">&quot;my_file&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;@&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$local_directory</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'shreya.jpg'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">&quot;upload&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;Upload&quot;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$post_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span></pre></div></div>

<h3><a href='http://www.maheshchari.com/wp-content/uploads/2010/03/curl_image.zip'>Download Example</a></h3>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=538&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/upload-image-file-to-remote-server-with-php-curl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>multifile upload</title>
		<link>http://www.maheshchari.com/multifile-upload/</link>
		<comments>http://www.maheshchari.com/multifile-upload/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 12:09:45 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=179</guid>
		<description><![CDATA[Multiple file uploading tutorial with php
We already discussed about increasing file upload size and simple file upload  in my previous posts.now we discuss about the logic behind the multiple file upload.
Here we create unlimited file fields on the fly with javascript ,so that there is no limit.
uploader.php:-we process all the uploaded files and show [...]]]></description>
			<content:encoded><![CDATA[<h1>Multiple file uploading tutorial with php</h1>
<p>We already discussed about <a href="http://www.maheshchari.com/increase-php-file-upload-limit/">increasing file upload size</a> and <a href="http://www.maheshchari.com/simple-php-file-upload-tutorial/">simple file upload </a> in my previous posts.now we discuss about the logic behind the multiple file upload.<br />
Here we create unlimited file fields on the fly with javascript ,so that there is no limit.<br />
<strong>uploader.php:-</strong>we process all the uploaded files and show the results of uploaded files. remember to validate and filter the file types please view my previous post.</p>
<h3>Please Download Source Code To View it</h3>
<p><a href='http://www.maheshchari.com/wp-content/uploads/2009/06/handling-multiple-file-upload-php.rar'>handling-multiple-file-upload-php</a></p>
<h3>Javascript Code</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> add_file_field<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> container<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'file_container'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> file_field<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
file_field.<span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'images[]'</span><span style="color: #339933;">;</span>
file_field.<span style="color: #660066;">type</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'file'</span><span style="color: #339933;">;</span>
container.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>file_field<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> br_field<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'br'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
container.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>br_field<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>HTML Code</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;uploader.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; name=&quot;mutiple_file_upload_form&quot; id=&quot;mutiple_file_upload_form&quot;&gt;
  &lt;h1&gt;Advanced Multiple File Upload Script Example&lt;/h1&gt;&lt;div id=&quot;file_container&quot;&gt;
    &lt;input name=&quot;images[]&quot; type=&quot;file&quot;  /&gt;
    &lt;br /&gt;
  &lt;/div&gt;
  &lt;a href=&quot;javascript:void(0);&quot; onClick=&quot;add_file_field();&quot;&gt;Add another&lt;/a&gt;&lt;br /&gt;
  &lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<h3>PHP Code</h3>

<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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$number_of_file_fields</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$number_of_uploaded_files</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$number_of_moved_files</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$uploaded_files</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$upload_directory</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__file__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/uploaded/'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//set upload directory</span>
    <span style="color: #009933; font-style: italic;">/**
     * we get a $_FILES['images'] array ,
     * we procee this array while iterating with simple for loop 
     * you can check this array by print_r($_FILES['images']); 
     */</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'images'</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: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$number_of_file_fields</span><span style="color: #339933;">++;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'images'</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: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//check if file field empty or not</span>
            <span style="color: #000088;">$number_of_uploaded_files</span><span style="color: #339933;">++;</span>
            <span style="color: #000088;">$uploaded_files</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'images'</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: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'images'</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: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$upload_directory</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'images'</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: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$number_of_moved_files</span><span style="color: #339933;">++;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Number of File fields created <span style="color: #006699; font-weight: bold;">$number_of_file_fields</span>.&lt;br/&gt; &quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Number of files submitted <span style="color: #006699; font-weight: bold;">$number_of_uploaded_files</span> . &lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Number of successfully moved files <span style="color: #006699; font-weight: bold;">$number_of_moved_files</span> . &lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;File Names are &lt;br/&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$uploaded_files</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Download Source Code</h3>
<p><a href='http://www.maheshchari.com/wp-content/uploads/2009/06/handling-multiple-file-upload-php.rar'>handling-multiple-file-upload-php</a><br />
<br/></p>
<h3>Screen Shots</h3>
<p><a href="http://www.maheshchari.com/wp-content/uploads/2009/06/handling-multiple-file-upload-example.jpg"><img src="http://www.maheshchari.com/wp-content/uploads/2009/06/handling-multiple-file-upload-example.jpg" alt="handling-multiple-file-upload-example" title="handling-multiple-file-upload-example" class="alignnone size-full wp-image-182" /></a><a href="http://www.maheshchari.com/wp-content/uploads/2009/06/handling-multiple-file-upload-result.jpg"><img src="http://www.maheshchari.com/wp-content/uploads/2009/06/handling-multiple-file-upload-result-300x130.jpg" alt="handling-multiple-file-upload-result" title="handling-multiple-file-upload-result" width="300" height="130" class="alignnone size-medium wp-image-183" /></a></p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=179&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/multifile-upload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>increase php file upload limit</title>
		<link>http://www.maheshchari.com/increase-php-file-upload-limit/</link>
		<comments>http://www.maheshchari.com/increase-php-file-upload-limit/#comments</comments>
		<pubDate>Wed, 20 May 2009 07:31:26 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=89</guid>
		<description><![CDATA[Increase file size upload limit using php.ini or htaccess
Any php web application or server configured with default values set in php.ini and  .htacess.  Generally almost web hosting providers configures the web application to optimum settings, which effects server bandwidth, server memory limit, server disk space, and peak security measures. For file uploading and [...]]]></description>
			<content:encoded><![CDATA[<h1>Increase file size upload limit using php.ini or htaccess</h1>
<p>Any php web application or server configured with default values set in <strong>php.ini</strong> and  <strong>.htacess</strong>.  Generally almost web hosting providers configures the web application to optimum settings, which effects server bandwidth, server memory limit, server disk space, and peak security measures. For file uploading and PHP script execution there is default configuration in <strong>PHP.ini</strong>. However almost hosting providers give chance to developer to customize this default configuration by override <strong>php.ini</strong> or<strong>. htaccess</strong> . some settings can be configured by <strong>ini_set()</strong>  method at run time of script.</p>
<h3>Default PHP.ini</h3>
<pre>
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = "${path}\tmp\"

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

;;;;;;;;;;;;;;;;;;;
; Resource Limits;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60	; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M      ; Maximum amount of memory a script may consume (128MB)
</pre>
<h3>Increasing file upload size by php.ini</h3>
<p><strong>File upload size affected by mainly below PHP settings.</strong><br />
file_uploads = On<br />
This setting must be on. It allows running uploads through HTTP.<br />
Ensure this value is on the value can be On/Off or 1/0 or true/false.<br />
upload_max_filesize = 20M<br />
This value limits the size of uploaded single file. Give it value what ever your requirements.<br />
post_max_size = 40M<br />
This value limits the size of all the uploaded content. For example upload_max_filesize is for single file, if we upload 3 files simultaneously each 15mb total 45mb so it exceeds post_max_size.<br />
Remember post_max_size must be larger about 40% of upload_max_filesize.</p>
<p>max_execution_time = 30<br />
Generally image uploading and manipulating with GD or Imagemagic consumes much time. So it may exceeds 30 seconds. You can modify whatever your requirements. When a script execution time exceeded by this limit the server stops the scripts or gives fatal error.</p>
<p>memory_limit = 128M<br />
Generally image uploading and manipulation with GD or Imagemagic consumes much server memory. When it exceeds this memory the server stops executing the script, then we see empty page or no response from server or we get a fatal error.</p>
<p>Completed example, to increase 10Mb<br />
upload_max_filesize = 10M ;<br />
post_max_size = 20M ;<br />
memory_limit = 128M</p>
<p>Copy the above settings into your php.ini and put it in your web root directory.</p>
<h3>Increasing file upload size by .htaccess</h3>
<p>php_value upload_max_filesize 10M<br />
php_value post_max_size 20M<br />
php_value memory_limit  128M</p>
<p>Copy the above settings into your .htaccess file and put it in your web root directory.<br />
Almost all web host providers give to override the .htacces ,so you can use above method.</p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=89&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/increase-php-file-upload-limit/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>simple PHP file upload tutorial</title>
		<link>http://www.maheshchari.com/simple-php-file-upload-tutorial/</link>
		<comments>http://www.maheshchari.com/simple-php-file-upload-tutorial/#comments</comments>
		<pubDate>Sat, 09 May 2009 06:19:34 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=48</guid>
		<description><![CDATA[A simple PHP file upload tutorial
This PHP file upload tutorial is concentrated on mainly for beginners. Generally we face many problems in file uploading. Like checking fie extensions on client and server side, processing file as our requirement.
For this we need two files called uploader.html and uploader.php
In uploader.html we do form validation and checking file [...]]]></description>
			<content:encoded><![CDATA[<h1>A simple PHP file upload tutorial</h1>
<p>This PHP file upload tutorial is concentrated on mainly for beginners. Generally we face many problems in file uploading. Like checking fie extensions on client and server side, processing file as our requirement.<br />
For this we need two files called<strong> uploader.html</strong> and <strong>uploader.php</strong><br />
In <strong>uploader.html</strong> we do form validation and checking file extensions.<br />
In <strong>uploader.php</strong> we do check for user submitted file extensions.</p>
<h3>Some observations&lt;</h3>
<ul>
<li> Always-set form method to POST</li>
<li> Always-set form encodedtype to multipart/form-data</li>
<li> Check file type on client side and server side also.</li>
<li> Increase the script time limit and memory limit to upload large file.</li>
<li> Don’t use web method (this method) to upload larger than 500mb,instead use ftp upload interface.</li>
</ul>
<p>Generally the default maximum upload file size less than 8mb.<br />
To upload the larger or bigger files read <a href="http://www.maheshchari.com/increase-php-file-upload-limit/">increase file upload limit</a></p>
<h3>Add a simple Form to page as shown below</h3>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form id=&quot;uploadform&quot; action=&quot;uploader.php&quot; enctype=&quot;multipart/form-data&quot; method=&quot;post&quot;&gt;
  &lt;label&gt;Upload File
  &lt;input id=&quot;filefield&quot; name=&quot;filefield&quot; type=&quot;file&quot; /&gt;
  &lt;/label&gt;
  &lt;label&gt;
  &lt;input id=&quot;Upload&quot; name=&quot;Upload&quot; type=&quot;submit&quot; value=&quot;Upload&quot; /&gt;
  &lt;!--
  This hidden input will force the  PHP max upload size.
  it may work on all servers.
   --&gt;
  &lt;input name=&quot;MAX_FILE_SIZE&quot; type=&quot;hidden&quot; value=&quot;100000&quot; /&gt;
  &lt;/label&gt;
&lt;/form&gt;</pre></div></div>

<h3>Add validation script to page as shown below</h3>

<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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #003366; font-weight: bold;">function</span> validatefile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> myform<span style="color: #339933;">=</span>document.<span style="color: #660066;">uploadform</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">//reference to form </span>
		<span style="color: #003366; font-weight: bold;">var</span> file_field_value<span style="color: #339933;">=</span>myform.<span style="color: #660066;">filefield</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//access form value with dom model</span>
		<span style="color: #003366; font-weight: bold;">var</span> error<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>file_field_value<span style="color: #339933;">==</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				error<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot;Please Select A file.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #003366; font-weight: bold;">var</span> allowed_extensions<span style="color: #339933;">=</span><span style="color: #009966; font-style: italic;">/(jpg|jpeg|bmp|giff|doc|docx|pdf)$/</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//check for allowed extension it is simple regular expression</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>file_field_value.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span>allowed_extensions<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				error<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot;Please select only jpeg or jpg or bmp or giff or doc or pdf .&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>error<span style="color: #339933;">!=</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>  <span style="color: #006600; font-style: italic;">//check for any errors</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">//if error alert error</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">//return to form don't submit to action page</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">// every thing going fine return true allow form to submit the data.</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h3>Check file status and process the page on server side.</h3>

<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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Upload'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #666666; font-style: italic;">//check if form submitted</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filefield'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//check for image submitted</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filefield'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// check for error re file</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Error: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;filefield&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//every thing fine file successfully uploaded to server</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'File not uploaded.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// exit script</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>now a simple validation and uploading the file</h3>

<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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You can&quot;t access this file directly'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">//avoid direct accessing to this file.</span>
&nbsp;
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Upload'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #666666; font-style: italic;">//check if form submitted</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filefield'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//check for image submitted</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filefield'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// check for error re file</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Error: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;filefield&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$file</span><span style="color: #339933;">=</span><span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filefield'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//every thing fine. file successfully uploaded to server</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'File not uploaded.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// exit script</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000088;">$upload_directory</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'uploaded/'</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$ext_str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;gif,jpg,jpeg,mp3,tiff,bmp,doc,docx,ppt,pptx,txt,pdf&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$allowed_extensions</span><span style="color: #339933;">=</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$ext_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$max_file_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10485760</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//10 mb remember 1024bytes =1kbytes</span>
 <span style="color: #000088;">$overwrite_file</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">/* 
 upload directory check 
  */</span>
 <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</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: #000088;">$upload_directory</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//check if upload directory exists or not</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mkdir</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$upload_directory</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//if directory doesn't exists try to create it,if fails warn user</span>
                    <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">chmod</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$upload_directory</span><span style="color: #339933;">,</span> <span style="color: #208080;">0777</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//change file permisson to write,read,execute</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>  <span style="color: #666666; font-style: italic;">//if can't make a directory warn the user and exit</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'There is no uploade directory or i can&quot; create the upload directory'</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;">/* 
check allowed extensions here
 */</span> 
<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</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: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</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: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//get file extension from last sub string from last . character</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ext</span><span style="color: #339933;">,</span> <span style="color: #000088;">$allowed_extensions</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'only'</span><span style="color: #339933;">.</span><span style="color: #000088;">$ext_str</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' files allowed to upload'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// exit the script by warning</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* 
check file size of the file if it exceeds the specified size warn user
 */</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;=</span><span style="color: #000088;">$max_file_size</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'only the file less than '</span><span style="color: #339933;">.</span><span style="color: #000088;">$max_file_size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'mb  allowed to upload'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// exit the script by warning</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* 
check if the file already exists or not in the upload directory
 */</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$overwrite_file</span> and <span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$upload_directory</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the file  '</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</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: #0000ff;">' already exists.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// exit the script by warning</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</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;">$upload_directory</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The file can&quot;t moved to target directory..'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//file can't moved with unknown reasons likr cleaning of server temperory files cleaning</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/* 
Hurrey we uploaded a file to server successfully.
 */</span></pre></td></tr></table></div>

<h3>Download Source Code</h3>
<p><a href="http://www.maheshchari.com/wp-content/uploads/2009/05/simple_php_file_uploade_by_maheshchari.rar">Download Source Code Link(3kb)</a></p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=48&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/simple-php-file-upload-tutorial/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
