{"id":15057,"date":"2016-11-01T16:15:54","date_gmt":"2016-11-01T14:15:54","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=15057"},"modified":"2018-01-09T10:10:53","modified_gmt":"2018-01-09T08:10:53","slug":"php-file-upload-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/","title":{"rendered":"PHP File Upload Example"},"content":{"rendered":"<p>[ads1]File uploads has now become an integral part of many, if not all social apps (both web apps and mobile apps).<\/p>\n<p>The ability to view, upload and share pictures, videos and other media types are components of a viral social app. For this singular reason most web masters and app developers incorporate file uploads into the social apps they develop.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;8njY7i2QRy6sg8pg&#8217;]<br \/>\n&nbsp;<br \/>\nFile uploads are also used to collect needed materials from users. File uploads are used in quite a number of different applications (too numerous to mention here). How to add a file upload system into a web app is now an important skill every (PHP) web developer should possess. In this example we are going to learn how to add a file upload mechanism to a website or web app.<br \/>\nFor this example we will use:<\/p>\n<ul>\n<li>A computer with PHP &gt;= 5.5 installed<\/li>\n<li>notepad++<\/li>\n<\/ul>\n<h2>1. Getting Started<\/h2>\n<p>File uploads are created with the HTML <code>input<\/code> tag which is always inside a <code> form <\/code> tag. We are going to get started by taking a short crash course into HTML forms (what they are and how to effectively use them) if you are already familar with HTML form please skip the next section.<\/p>\n<h3>1.1 HTML Forms<\/h3>\n<p>HTML forms are created with the opening <code> &lt;form&gt; <\/code>and closing <code>&lt;form&gt;\u00a0<\/code>tag. The form tag defines an html form. Form elements are different, they can be text fields, checkboxes, radio buttons, submit buttons, and more.<\/p>\n<p>An HTML form contains an action and a method attribute. The \u201caction\u201d attribute in a form tag tells the form where to submit its content while the \u201cmethod\u201d attribute lets the form know which method to use when transmitting its content. The method attribute can either be GET or POST.<\/p>\n<p>Some attributes of the GET method are:<\/p>\n<ul>\n<li>The get method is visible to everyone<\/li>\n<li>The GET method sends encoded user information appended to the page. e.g http:\/\/www.server.com\/index.htm?name1=value<\/li>\n<li>The GET method has a limitation of about 2000 characters<\/li>\n<li>The GET method should never be used to transmit sensitive information(e.g passwords)<\/li>\n<li>PHP provides $_GET associative array to access all the data sent using GET method.<\/li>\n<\/ul>\n<p>Some attributes of the POST method are:<\/p>\n<ul>\n<li>Information sent with POST is invisible to others<\/li>\n<li>It has no limitations on data size<\/li>\n<li>PHP provides $_POST associative array to access all the information sent using POST method<\/li>\n<\/ul>\n<p>We have learnt how to create HTML forms and how data in HTML forms are sent to the server. How do we write a script that handles and manipulates the form data when it arrives at the server?<br \/>\nFirst of all, the form action attribute needs to contain the URL of the PHP script that will handle the form. e.g <code> &lt; form action=\"index.php\" method =\"post\" &gt;.\u00a0<\/code>Next we need to create the form handler ( e.g index.php ).<\/p>\n<p>When the form data gets to the server the script \u201cindex.php\u201d is called. The script then needs to read the form data and act on it. We use $_GET and $_POST superglobal arrays to read data sent to the server.<br \/>\n$_GET: Contains a list of all the field names and values sent by a form using the GET method.<br \/>\n$_POST: Contains a list of all the field names and values sent by a form using the POST method.<\/p>\n<p>For example we have created a form using the GET method and the form contains a text field<br \/>\n<code>&lt; input type=text name=text &gt;.<\/code><br \/>\nWe can access the data in this form field by using the $_GET superglobal array<br \/>\n<code>$text=$_GET[\"text\"];<\/code><\/p>\n<p><span style=\"text-decoration: underline;\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush:php\"> \r\n&lt;?php\r\n&lt;!DOCTYPE html&gt; \r\n &lt;html lang=\"en\"&gt; \r\n &lt;head&gt;    \r\n &lt;title&gt;Programming Club Membership Form&lt;\/title&gt;     \r\n&lt;\/head&gt;\r\n &lt;body&gt;    \r\n &lt;h1&gt;  Programming Club Membership Form &lt;\/h1&gt;\r\n    &lt;p&gt;Thanks for choosing to join our Programming Language Club.&lt;\/p&gt;\r\n\t\r\n\t\r\n    &lt;form action=index.php method=post&gt;   \r\n\t&lt;div style=\"width: 30em;\" &gt;\r\n        &lt;label for=firstName&gt; First name &lt;\/label&gt; &lt;br&gt;        &lt;input type=text name=firstName id=firstName required \/&gt; &lt;br&gt; &lt;br&gt;\r\n        &lt;label for=lastName&gt; Last name &lt;\/label&gt; &lt;br&gt;       &lt;input type=text name=lastName id=lastName  required\/&gt; &lt;br&gt; &lt;br&gt;\r\n        &lt;label for=password1&gt; Choose a password &lt;\/label&gt; &lt;br&gt;       &lt;input type=password name=password1 id=password1 required \/&gt; &lt;br&gt;  &lt;br&gt;  \r\n\t\t&lt;label for=password2&gt; Retype password &lt;\/label&gt;&lt;br&gt;        &lt;input type=password name=password2 id=password2 required \/&gt; &lt;br&gt; &lt;br&gt;\r\n        &lt;label for=genderMale&gt; Are you male... &lt;\/label&gt;        &lt;input type=radio name=gender id=genderMale value=Male \/&gt;       \r\n\t\t&lt;label for=genderFemale&gt;...or female?&lt;\/label&gt; &lt;input type=radio name=gender id=genderFemale value=Female checked \/&gt; &lt;br&gt; &lt;br&gt;\r\n        &lt;label for=favoriteWidget&gt; What's your favorite programming language? &lt;\/label&gt;        &lt;select name=favoriteWidget id=favoriteWidget size=1&gt;        \r\n\t\t&lt;option value=java&gt; Java &lt;\/option&gt;     \r\n\t\t&lt;option value=php&gt; PHP &lt;\/option&gt;          \r\n\t\t&lt;option value=phyton&gt; PHYTON &lt;\/option&gt;     \r\n\t\t&lt;\/select&gt; &lt;br&gt; &lt;br&gt;\r\n        &lt;label for=newsletter&gt; Do you want to receive our newsletter? &lt;\/label&gt;        \r\n\t\t&lt;input type=checkbox name=newsletter id=newsletter value=yes \/&gt; &lt;br&gt; &lt;br&gt;\r\n        &lt;label for=comments&gt; Any comments? &lt;\/label&gt;       \r\n\t\t&lt;textarea name=comments id=comments rows=4 cols=50&gt; &lt;\/textarea&gt;\r\n        &lt;div style=\u201dclear: both;\u201d&gt;         \r\n\t&lt;input type=submit name=submitButton id=submitButton value=Send Details \/&gt;       \r\n\t&lt;input type=reset name=resetButton id=resetButton value=\"Reset Form\" style=\"margin-right: 20px;\" \/&gt;      \r\n\t&lt;\/div&gt;     \r\n\t&lt;\/div&gt;\r\n\t\r\n\t&lt;\/form&gt;\r\n  &lt;\/body&gt; \r\n&lt;\/html&gt;\r\n<\/pre>\n<p>The script above is a typical example of an HTML form. I particularly love it because it features different elements that can be used in an html form.<\/p>\n<h3>1.2 PHP File Upload<\/h3>\n<p>To get started with file uploads, make sure PHP is configured to allow file uploads. In your php.ini file search for file_upload and set it to on. If you dont know how to locate your php.ini file just create a script and add the line below to it.<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n\r\necho phpinfo();\r\n\r\n?&gt;\r\n\r\n<\/pre>\n<p>The above code prints out the PHP information for your server. Check the section named &#8220;loaded configuration file&#8221; you will see the path to the php.ini file.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush:php\"> \r\n\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;body&gt;\r\n&lt;form action =\"file.php\" method =\"post\" enctype =\"multipart\/form-data\"&gt;\r\n&lt;label for=firstName&gt; Select the image to upload: &lt;\/label&gt; &lt;br&gt; &lt;br&gt;\r\n&lt;input type=\"file\" name=\"fileToUpload\" id =\"fileToUpload\"&gt; &lt;br&gt; &lt;br&gt;\r\n&lt;input type=\"submit\" value =\"Upload Image\" name=\"submit\"&gt; &lt;br&gt;\r\n&lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>In the HTML file above, we create an HTML form that allows users to upload and submit a file. The HTML file displays an upload file button and a submit button.<\/p>\n<p>Some rules that must be followed for the HTML form above to work are:<\/p>\n<ul>\n<li>Make sure that the form uses method=&#8221;post&#8221;<\/li>\n<li>The form also needs the following attribute: enctype=&#8221;multipart\/form-data&#8221;. It specifies which content-type to use when submitting the form<br \/>\nWithout the requirements above, the file upload will not work.<\/li>\n<\/ul>\n<p>Other things to take cognisance of are:<\/p>\n<ul>\n<li>The <code>type=\"file\" <\/code>attribute of the tag shows the input field as a file-select control, with a &#8220;Browse&#8221; button next to the input control<\/li>\n<\/ul>\n<p>The form above sends the data inputed by the user to a script named &#8220;file.php&#8221;<\/p>\n<p><span style=\"text-decoration: underline;\"><em> file.php <\/em><\/span><\/p>\n<pre class=\"brush:php\"> \r\n&lt;?php\r\n$save_dir =\r\n\"uploads\/\" ;\r\n$save_file = $save_dir . basename( $_FILES\r\n[ \"fileToUpload\" ][ \"name\" ]);\r\n$uploadOk = 1;\r\n$fileType = pathinfo($save_file,PATHINFO_EXTENSION);\r\n\/\/ Check if image file is a actual image or  a fake image\r\nif ( isset($_POST\r\n[ \"submit\" ])) {\r\n$check = getimagesize( $_FILES\r\n[ \"fileToUpload\" ][ \"tmp_name\" ]);\r\nif ($check !== false) {\/\/returned a valid image\r\necho \"File is a valid image - \" . $check[ \"mime\" ] . \". &lt;br&gt;\" ;\r\n$isuploadok =true ;\r\n} else {\/\/whatever was returned is not a valid image\r\necho \"File is not an image. &lt;br&gt;\" ;\r\n$isuploadok = false;\r\n}\r\n}\r\n\/\/ Check if file already exists\r\nif (file_exists($save_file)) {\r\necho \"Sorry, file already exists. &lt;br&gt;\" ;\/\/the uploaded file already exists on the server\r\n$isuploadok = false;\/\/define error code\r\n}\r\n\/\/ Check file size\r\nif ($_FILES\r\n[ \"fileToUpload\" ][ \"size\" ] &gt; 500000 ) {\/\/get the file size and check if it too large\r\necho \"Sorry, your file is too large. &lt;br&gt;\" ;\r\n$isuploadok = false;\r\n}\r\n\/\/ Allow only some certain file formats(jpg, png, jpeg and gif)\r\nif ($fileType !=\r\n\"jpg\" &amp;&amp; $fileType != \"png\" &amp;&amp; $fileType !=\r\n\"jpeg\"\r\n&amp;&amp; $fileType !=\r\n\"gif\" ) {\r\necho \"Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed. &lt;br&gt;\" ;\r\n$isuploadok =false;\r\n}\r\n\/\/ \r\nif (!$isuploadok) {\/\/ this upload is not ok there is an error associated with it\r\necho \"Sorry, your file was not uploaded. &lt;br&gt;\" ;\r\n\/\/ if everything is ok, try to upload file\r\n} else {\/\/upload very ok\r\nif (move_uploaded_file( $_FILES\r\n[ \"fileToUpload\" ][ \"tmp_name\" ], $save_file)) {\/\/try to move file\r\necho \"The file \" . basename( $_FILES\r\n[ \"fileToUpload\" ][ \"name\" ]). \" has been uploaded. &lt;br&gt;\" ;\r\n} else {\/\/file was not moved successfully\r\necho \"Sorry, there was an error uploading your file. &lt;br&gt;\";\r\n}\r\n}\r\n?&gt;\r\n\r\n<\/pre>\n<p>The script above handles data sent from the file upload input.<\/p>\n<h2>2. Summary<\/h2>\n<p>In this example we learnt about file uploads, and how to handle file upload data with PHP. We also took a very short crash course into HTML forms.<\/p>\n<h2>3. Download the source code<\/h2>\n<div class=\"download\">\n<p><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here:\u00a0<strong><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/10\/fileuploadexample.zip\">fileuploadexample<\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>[ads1]File uploads has now become an integral part of many, if not all social apps (both web apps and mobile apps). The ability to view, upload and share pictures, videos and other media types are components of a viral social app. For this singular reason most web masters and app developers incorporate file uploads into &hellip;<\/p>\n","protected":false},"author":164,"featured_media":930,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[122,401],"class_list":["post-15057","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php","tag-php-file-upload"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP File Upload Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"File uploads has now become an integral part of many, if not all social apps (both web apps and mobile apps). The ability to view, upload and share\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP File Upload Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"File uploads has now become an integral part of many, if not all social apps (both web apps and mobile apps). The ability to view, upload and share\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-01T14:15:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T08:10:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Olayemi Odunayo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Olayemi Odunayo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/\"},\"author\":{\"name\":\"Olayemi Odunayo\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8\"},\"headline\":\"PHP File Upload Example\",\"datePublished\":\"2016-11-01T14:15:54+00:00\",\"dateModified\":\"2018-01-09T08:10:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/\"},\"wordCount\":895,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"keywords\":[\"php\",\"php file upload\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/\",\"name\":\"PHP File Upload Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"datePublished\":\"2016-11-01T14:15:54+00:00\",\"dateModified\":\"2018-01-09T08:10:53+00:00\",\"description\":\"File uploads has now become an integral part of many, if not all social apps (both web apps and mobile apps). The ability to view, upload and share\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/php\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP File Upload Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8\",\"name\":\"Olayemi Odunayo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g\",\"caption\":\"Olayemi Odunayo\"},\"description\":\"I am a programmer and web developer, who has experience in developing websites and writing desktop and mobile applications. I have worked with both schematic and schemaless databases. I am also familiar with third party API and working with cloud servers. I do programming on the client side with Java, JavaScript, html, Ajax and CSS while I use PHP for server side programming.\",\"sameAs\":[\"https:\/\/www.webcodegeeks.com\/\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/olayemi-odunayo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP File Upload Example - Web Code Geeks - 2026","description":"File uploads has now become an integral part of many, if not all social apps (both web apps and mobile apps). The ability to view, upload and share","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/","og_locale":"en_US","og_type":"article","og_title":"PHP File Upload Example - Web Code Geeks - 2026","og_description":"File uploads has now become an integral part of many, if not all social apps (both web apps and mobile apps). The ability to view, upload and share","og_url":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-11-01T14:15:54+00:00","article_modified_time":"2018-01-09T08:10:53+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","type":"image\/jpeg"}],"author":"Olayemi Odunayo","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Olayemi Odunayo","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/"},"author":{"name":"Olayemi Odunayo","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8"},"headline":"PHP File Upload Example","datePublished":"2016-11-01T14:15:54+00:00","dateModified":"2018-01-09T08:10:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/"},"wordCount":895,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","keywords":["php","php file upload"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/","url":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/","name":"PHP File Upload Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","datePublished":"2016-11-01T14:15:54+00:00","dateModified":"2018-01-09T08:10:53+00:00","description":"File uploads has now become an integral part of many, if not all social apps (both web apps and mobile apps). The ability to view, upload and share","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/php\/php-file-upload-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"PHP","item":"https:\/\/www.webcodegeeks.com\/category\/php\/"},{"@type":"ListItem","position":3,"name":"PHP File Upload Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/417918d9b5811210265e8590509718b8","name":"Olayemi Odunayo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/016b2a353262962fceecf5c274161cd9ef60fdf1593ec95e71d37f5fd9b444f6?s=96&d=mm&r=g","caption":"Olayemi Odunayo"},"description":"I am a programmer and web developer, who has experience in developing websites and writing desktop and mobile applications. I have worked with both schematic and schemaless databases. I am also familiar with third party API and working with cloud servers. I do programming on the client side with Java, JavaScript, html, Ajax and CSS while I use PHP for server side programming.","sameAs":["https:\/\/www.webcodegeeks.com\/"],"url":"https:\/\/www.webcodegeeks.com\/author\/olayemi-odunayo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/15057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/164"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=15057"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/15057\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/930"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=15057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=15057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=15057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}