{"id":350,"date":"2010-08-05T01:07:11","date_gmt":"2010-08-05T05:07:11","guid":{"rendered":"http:\/\/www.searchenginegenie.com\/programming-blog\/?p=350"},"modified":"2012-12-11T02:34:46","modified_gmt":"2012-12-11T06:34:46","slug":"to-upload-a-file-using-php","status":"publish","type":"post","link":"https:\/\/www.searchenginegenie.com\/programming-blog\/to-upload-a-file-using-php\/","title":{"rendered":"To upload a file using php"},"content":{"rendered":"<p><strong>Steps:<\/strong><\/p>\n<p><strong>1. Create new html file and copy upload.html code and save it as upload.html.<\/strong><\/p>\n<p><strong>2. Create new php file and copy uploader.php code and save it as uploader.php.<\/strong><\/p>\n<p><strong>3. Run upload.html, then it will display the html data.<\/strong><\/p>\n<p><strong>4. Click browse button and select any file or image and press upload button.<\/strong><\/p>\n<p><strong>5. Then it will transfer that specific file or image to the created folder and display the output as file is uploaded.<\/strong><\/p>\n<p><strong>upload.html:<\/strong><\/p>\n<p>[php]<\/p>\n<p>&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;<br \/>\n &lt;html xmlns=&quot;http:\/\/www.w3.org\/1999\/xhtml&quot;&gt;<br \/>\n &lt;head&gt;<br \/>\n &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=iso-8859-1&quot; \/&gt;<br \/>\n &lt;title&gt;upload&lt;\/title&gt;<br \/>\n &lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<br \/>\n &lt;form enctype=&quot;multipart\/form-data&quot; method=&quot;post&quot; action=&quot;uploader.php&quot;&gt;<br \/>\n &lt;input type=&quot;file&quot; name=&quot;file&quot; \/&gt;<br \/>\n &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;upload&quot; \/&gt;<br \/>\n &lt;\/form&gt;<br \/>\n &lt;\/body&gt;<br \/>\n &lt;\/html&gt;<\/p>\n<p>[\/php]<\/p>\n<p>It displays the output as:<\/p>\n<form action=\"uploader.php\" method=\"post\" enctype=\"multipart\/form-data\"><input type=\"file\" name=\"file\" \/><br \/>\n<input type=\"submit\" name=\"submit\" value=\"upload\" \/><\/form>\n<form action=\"uploader.php\" method=\"post\" enctype=\"multipart\/form-data\"><strong>uploader.php<\/strong><\/form>\n<form action=\"uploader.php\" method=\"post\" enctype=\"multipart\/form-data\">[php]&lt;\/form&gt;&lt;form action=&quot;uploader.php&quot; method=&quot;post&quot; enctype=&quot;multipart\/form-data&quot;&gt;&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;<br \/>\n &lt;html xmlns=&quot;http:\/\/www.w3.org\/1999\/xhtml&quot;&gt;<br \/>\n &lt;head&gt;<br \/>\n &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=iso-8859-1&quot; \/&gt;<br \/>\n &lt;title&gt;Untitled Document&lt;\/title&gt;<br \/>\n&lt;\/head&gt;&lt;body&gt;<br \/>\n &lt;?php<br \/>\n if(isset($_REQUEST[&#8216;submit&#8217;]))<br \/>\n {<br \/>\n $to=&quot;uploaded\/&quot;.$_FILES[&#8216;file&#8217;][&#8216;name&#8217;];<br \/>\n move_uploaded_file($_FILES[&#8216;file&#8217;][&#8216;tmp_name&#8217;],$to);<br \/>\n echo &quot;file is uploaded&quot;;<\/p>\n<p>}<br \/>\n ?&gt;<br \/>\n &lt;\/body&gt;<br \/>\n &lt;\/html&gt;<\/p>\n<p>[\/php]<\/p>\n<p>\/\/create a new folder uploaded<\/p>\n<\/form>\n","protected":false},"excerpt":{"rendered":"<p>Steps: 1. Create new html file and copy upload.html code and save it as upload.html. 2. Create new php file and copy uploader.php code and save it as uploader.php. 3. Run upload.html, then it will display the html data. 4. Click browse button and select any file or image and press upload button. 5. Then [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[15],"class_list":["post-350","post","type-post","status-publish","format-standard","hentry","category-php","tag-php-code"],"_links":{"self":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/comments?post=350"}],"version-history":[{"count":5,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/350\/revisions"}],"predecessor-version":[{"id":353,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/posts\/350\/revisions\/353"}],"wp:attachment":[{"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/media?parent=350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/categories?post=350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.searchenginegenie.com\/programming-blog\/wp-json\/wp\/v2\/tags?post=350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}