{"id":1253,"date":"2016-02-14T18:44:25","date_gmt":"2016-02-14T18:44:25","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=1253"},"modified":"2016-04-22T17:12:05","modified_gmt":"2016-04-22T17:12:05","slug":"upload-file-using-javascript-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/","title":{"rendered":"Upload file using JavaScript and PHP"},"content":{"rendered":"<p>We&#8217;ve already published multiple ways for file upload. Today we&#8217;ll try to upload a file with an interesting way. This tutorial will show you how to <b>upload file using JavaScript and PHP<\/b>. You don&#8217;t need to use jQuery or Ajax for upload file without page refresh. Using iframe, JavaScript and PHP, you can easily upload file to the server.<\/p>\n<p>Before starting to take a look at the folders and files structure.<\/p>\n<div><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-javascript-php-folders-files-structure-by-codexworld.png\" alt=\"upload-file-javascript-php-folders-files-structure-by-codexworld\" width=\"313\" height=\"143\" class=\"alignnone size-full wp-image-1254\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-javascript-php-folders-files-structure-by-codexworld.png 313w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-javascript-php-folders-files-structure-by-codexworld-300x137.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-javascript-php-folders-files-structure-by-codexworld-200x91.png 200w\" sizes=\"auto, (max-width: 313px) 100vw, 313px\" \/><\/div>\n<p>As per the above files structure, CSS and image file is stored in the <code>assets\/<\/code> directory.  <\/p>\n<h2><code>index.html<\/code> File<\/h2>\n<p>The <code>index.html<\/code> file contains HTML and JavaScript code.<br \/>\n<b>JavaScript:<\/b><br \/>\nWe&#8217;ve created two methods <code>startUpload()<\/code>, and <code>stopUpload()<\/code>.<br \/>\n<code>startUpload()<\/code>&nbsp;&#8211;&nbsp;This method shows the loader image and hide the upload form when the upload is starting.<br \/>\n<code>stopUpload()<\/code>&nbsp;&#8211;&nbsp;This method accepts two parameters, <code>success<\/code>, and <code>uploadedFile<\/code>. If success is 1, the preview would be generated of the uploaded file. Otherwise, error message would be shown.<\/p>\n<pre>&lt;<span style=\"color:#bf4f24\">script<\/span> <span style=\"color:#bf4f24\">type<\/span>=<span style=\"color:#0b6125\">\"text\/javascript\"<\/span>>\r\n<span style=\"color:#a71d5d;font-style:italic\">function<\/span> <span style=\"color:#bf4f24\">startUpload<\/span>(){\r\n    <span style=\"color:#691c97\">document<\/span>.<span style=\"color:#693a17\">getElementById<\/span>(<span style=\"color:#0b6125\">'uploadProcess'<\/span>).<span style=\"color:#b4371f\">style<\/span>.<span style=\"color:#b4371f\">visibility<\/span> <span style=\"color:#794938\">=<\/span> <span style=\"color:#0b6125\">'visible'<\/span>;\r\n    <span style=\"color:#691c97\">document<\/span>.<span style=\"color:#693a17\">getElementById<\/span>(<span style=\"color:#0b6125\">'uploadForm'<\/span>).<span style=\"color:#b4371f\">style<\/span>.<span style=\"color:#b4371f\">visibility<\/span> <span style=\"color:#794938\">=<\/span> <span style=\"color:#0b6125\">'hidden'<\/span>;\r\n    <span style=\"color:#794938\">return<\/span> <span style=\"color:#811f24;font-weight:700\">true<\/span>;\r\n}\r\n\r\n<span style=\"color:#a71d5d;font-style:italic\">function<\/span> <span style=\"color:#bf4f24\">stopUpload<\/span>(success,uploadedFile){\r\n    <span style=\"color:#a71d5d;font-style:italic\">var<\/span> result <span style=\"color:#794938\">=<\/span> <span style=\"color:#0b6125\">''<\/span>;\r\n    <span style=\"color:#794938\">if<\/span> (success <span style=\"color:#794938\">==<\/span> <span style=\"color:#811f24;font-weight:700\">1<\/span>){\r\n        result <span style=\"color:#794938\">=<\/span> <span style=\"color:#0b6125\">'&lt;span class=\"sucess-msg\">The file was uploaded successfully!&lt;<span style=\"color:#696969;font-weight:700\">\\\/<\/span>span>&lt;br\/>&lt;br\/>'<\/span>;\r\n        <span style=\"color:#5a525f;font-style:italic\">\/\/Uploaded file preview<\/span>\r\n        <span style=\"color:#a71d5d;font-style:italic\">var<\/span> embed <span style=\"color:#794938\">=<\/span> <span style=\"color:#691c97\">document<\/span>.<span style=\"color:#693a17\">getElementById<\/span>(<span style=\"color:#0b6125\">\"UploadedFile\"<\/span>);\r\n        <span style=\"color:#a71d5d;font-style:italic\">var<\/span> clone <span style=\"color:#794938\">=<\/span> embed.<span style=\"color:#693a17\">cloneNode<\/span>(<span style=\"color:#811f24;font-weight:700\">true<\/span>);\r\n        clone.<span style=\"color:#693a17\">setAttribute<\/span>(<span style=\"color:#0b6125\">'src'<\/span>,uploadedFile);\r\n        embed.<span style=\"color:#b4371f\">parentNode<\/span>.<span style=\"color:#693a17\">replaceChild<\/span>(clone,embed);\r\n    }<span style=\"color:#794938\">else<\/span> {\r\n       result <span style=\"color:#794938\">=<\/span> <span style=\"color:#0b6125\">'&lt;span class=\"error-msg\">There was an error during file upload!&lt;<span style=\"color:#696969;font-weight:700\">\\\/<\/span>span>&lt;br\/>&lt;br\/>'<\/span>;\r\n    }\r\n    <span style=\"color:#691c97\">document<\/span>.<span style=\"color:#693a17\">getElementById<\/span>(<span style=\"color:#0b6125\">'uploadProcess'<\/span>).<span style=\"color:#b4371f\">style<\/span>.<span style=\"color:#b4371f\">visibility<\/span> <span style=\"color:#794938\">=<\/span> <span style=\"color:#0b6125\">'hidden'<\/span>;\r\n    <span style=\"color:#691c97\">document<\/span>.<span style=\"color:#693a17\">getElementById<\/span>(<span style=\"color:#0b6125\">'uploadForm'<\/span>).innerHTML <span style=\"color:#794938\">=<\/span> result <span style=\"color:#794938\">+<\/span> <span style=\"color:#0b6125\">'&lt;label>File: &lt;input name=\"myfile\" type=\"file\" size=\"30\" \/>&lt;<span style=\"color:#696969;font-weight:700\">\\\/<\/span>label>&lt;label>&lt;input type=\"submit\" name=\"submitBtn\" class=\"sbtn\" value=\"Upload\" \/>&lt;<span style=\"color:#696969;font-weight:700\">\\\/<\/span>label>'<\/span>;\r\n    <span style=\"color:#691c97\">document<\/span>.<span style=\"color:#693a17\">getElementById<\/span>(<span style=\"color:#0b6125\">'uploadForm'<\/span>).<span style=\"color:#b4371f\">style<\/span>.<span style=\"color:#b4371f\">visibility<\/span> <span style=\"color:#794938\">=<\/span> <span style=\"color:#0b6125\">'visible'<\/span>;      \r\n    <span style=\"color:#794938\">return<\/span> <span style=\"color:#811f24;font-weight:700\">true<\/span>;   \r\n}\r\n&lt;\/<span style=\"color:#bf4f24\">script<\/span>>\r\n<\/pre>\n<p><b>HTML:<\/b><br \/>\nWe&#8217;ve used HTML &lt;<span style=\"color:#bf4f24\">form<\/span>> target attribute to display the response into the iframe. The upload form will submit to the <code>upload.php<\/code> file and the response will display into an iframe with <code>id=\"uploadTarget\"<\/code>.<\/p>\n<pre>&lt;<span style=\"color:#bf4f24\">form<\/span> <span style=\"color:#bf4f24\">action<\/span>=<span style=\"color:#0b6125\">\"upload.php\"<\/span> <span style=\"color:#bf4f24\">method<\/span>=<span style=\"color:#0b6125\">\"post\"<\/span> <span style=\"color:#bf4f24\">enctype<\/span>=<span style=\"color:#0b6125\">\"multipart\/form-data\"<\/span> <span style=\"color:#bf4f24\">target<\/span>=<span style=\"color:#0b6125\">\"uploadTarget\"<\/span> <span style=\"color:#bf4f24\">onsubmit<\/span>=<span style=\"color:#0b6125\">\"startUpload();\"<\/span> >\r\n    &lt;<span style=\"color:#bf4f24\">p<\/span> <span style=\"color:#bf4f24\">id<\/span><span style=\"color:#794938\">=<\/span><span style=\"color:#0b6125\">\"uploadProcess\"<\/span>>Uploading...&lt;<span style=\"color:#bf4f24\">br<\/span>\/>&lt;<span style=\"color:#bf4f24\">img<\/span> <span style=\"color:#bf4f24\">src<\/span>=<span style=\"color:#0b6125\">\"assets\/loader.gif\"<\/span> \/>&lt;<span style=\"color:#bf4f24\">br<\/span>\/>&lt;\/<span style=\"color:#bf4f24\">p<\/span>>\r\n    &lt;<span style=\"color:#bf4f24\">p<\/span> <span style=\"color:#bf4f24\">id<\/span><span style=\"color:#794938\">=<\/span><span style=\"color:#0b6125\">\"uploadForm\"<\/span> <span style=\"color:#bf4f24\">align<\/span>=<span style=\"color:#0b6125\">\"center\"<\/span>>&lt;<span style=\"color:#bf4f24\">br<\/span>\/>\r\n        &lt;<span style=\"color:#bf4f24\">label<\/span>>\r\n            File: &lt;<span style=\"color:#bf4f24\">input<\/span> <span style=\"color:#bf4f24\">name<\/span>=<span style=\"color:#0b6125\">\"myfile\"<\/span> <span style=\"color:#bf4f24\">type<\/span>=<span style=\"color:#0b6125\">\"file\"<\/span> <span style=\"color:#bf4f24\">size<\/span>=<span style=\"color:#0b6125\">\"30\"<\/span> \/>\r\n        &lt;\/<span style=\"color:#bf4f24\">label<\/span>>\r\n        &lt;<span style=\"color:#bf4f24\">label<\/span>>\r\n            &lt;<span style=\"color:#bf4f24\">input<\/span> <span style=\"color:#bf4f24\">type<\/span>=<span style=\"color:#0b6125\">\"submit\"<\/span> <span style=\"color:#bf4f24\">name<\/span>=<span style=\"color:#0b6125\">\"submitBtn\"<\/span> <span style=\"color:#bf4f24\">class<\/span>=<span style=\"color:#0b6125\">\"sbtn\"<\/span> <span style=\"color:#bf4f24\">value<\/span>=<span style=\"color:#0b6125\">\"Upload\"<\/span> \/>\r\n        &lt;\/<span style=\"color:#bf4f24\">label<\/span>>\r\n    &lt;\/<span style=\"color:#bf4f24\">p<\/span>>\r\n    &lt;<span style=\"color:#bf4f24\">iframe<\/span> <span style=\"color:#bf4f24\">id<\/span><span style=\"color:#794938\">=<\/span><span style=\"color:#0b6125\">\"uploadTarget\"<\/span> <span style=\"color:#bf4f24\">name<\/span>=<span style=\"color:#0b6125\">\"uploadTarget\"<\/span> <span style=\"color:#bf4f24\">src<\/span>=<span style=\"color:#0b6125\">\"#\"<\/span> <span style=\"color:#bf4f24\">style<\/span>=<span style=\"color:#0b6125\">\"width:0;height:0;border:0px solid #fff;\"<\/span>>&lt;\/<span style=\"color:#bf4f24\">iframe<\/span>>\r\n&lt;\/<span style=\"color:#bf4f24\">form<\/span>>\r\n<span style=\"color:#5a525f;font-style:italic\">&lt;!-- Uploaded file preview --><\/span>\r\n&lt;<span style=\"color:#bf4f24\">div<\/span>>\r\n    &lt;<span style=\"color:#bf4f24\">embed<\/span> <span style=\"color:#bf4f24\">id<\/span><span style=\"color:#794938\">=<\/span><span style=\"color:#0b6125\">\"UploadedFile\"<\/span> <span style=\"color:#bf4f24\">src<\/span>=<span style=\"color:#0b6125\">\"\"<\/span> <span style=\"color:#bf4f24\">width<\/span>=<span style=\"color:#0b6125\">\"390px\"<\/span> <span style=\"color:#bf4f24\">height<\/span>=<span style=\"color:#0b6125\">\"160px\"<\/span>>\r\n&lt;\/<span style=\"color:#bf4f24\">div<\/span>>\r\n<\/pre>\n<h2><code>upload.php<\/code> File<\/h2>\n<p>In the <code>upload.php<\/code> file, the file is uploaded using PHP and JavaScript <code>stopUpload()<\/code> method is called. File upload status and uploaded file name is passed into the <code>stopUpload()<\/code> method.<\/p>\n<pre><span style=\"color: #0000BB\">&lt;?php<br \/>&nbsp;&nbsp;&nbsp;&nbsp;$success&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$uploadedFile&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/File&nbsp;upload&nbsp;path<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$uploadPath&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'uploads\/'<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$targetPath&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$uploadPath&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">basename<\/span><span style=\"color: #007700\">(&nbsp;<\/span><span style=\"color: #0000BB\">$_FILES<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'myfile'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'name'<\/span><span style=\"color: #007700\">]);<br \/><br \/>&nbsp;&nbsp;&nbsp;&nbsp;if(@<\/span><span style=\"color: #0000BB\">move_uploaded_file<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_FILES<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'myfile'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'tmp_name'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$targetPath<\/span><span style=\"color: #007700\">)){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$success&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$uploadedFile&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$targetPath<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">sleep<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">1<\/span><span style=\"color: #007700\">);<br \/><\/span><span style=\"color: #0000BB\">?&gt;<br \/><\/span>&lt;<span style=\"color:#bf4f24\">script<\/span> <span style=\"color:#bf4f24\">type<\/span>=<span style=\"color:#0b6125\">\"text\/javascript\"<\/span>><span style=\"color:#691c97\">window<\/span>.<span style=\"color:#b4371f\">top<\/span>.<span style=\"color:#691c97\">window<\/span>.stopUpload(<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$success<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>,<span style=\"color:#0b6125\">'<\/span><span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$uploadedFile<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span style=\"color:#0b6125\">'<\/span>);&lt;\/<span style=\"color:#bf4f24\">script<\/span>><\/pre>\n<h2><code>style.css<\/code> File<\/h2>\n<p>Some CSS code has been used for styling the HTML content and placed all code together in the <code>style.css<\/code> file. You can find this file in the <a href=\"#ProjectDemoDownload\">source code package<\/a>.<\/p>\n<h2>Conclusion<\/h2>\n<p>This file upload process will help when you want to upload file without page refresh and without using the jQuery. Otherwise, you can <a href=\"http:\/\/www.codexworld.com\/upload-multiple-images-using-jquery-ajax-php\/\">upload multiple files using jQuery, Ajax, and PHP<\/a> or <a href=\"http:\/\/www.codexworld.com\/drag-and-drop-file-upload-using-dropzone-php\/\">Drag and drop file upload using DropzoneJS and PHP<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve already published multiple ways for file upload. Today we&#8217;ll try to upload a file with an interesting way. This tutorial will show you how to upload file using JavaScript and PHP. You don&#8217;t need <\/p>\n","protected":false},"author":1,"featured_media":1258,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[10],"tags":[56,66,14],"class_list":["post-1253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-file-upload","tag-javascript","tag-php","cat-10-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Upload file using JavaScript and PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"Upload file without page refresh using JavaScript and PHP \u2013 Learn how to upload file using JavaScript and PHP.\" \/>\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.codexworld.com\/upload-file-using-javascript-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Upload file using JavaScript and PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Upload file without page refresh using JavaScript and PHP \u2013 Learn how to upload file using JavaScript and PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-14T18:44:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-04-22T17:12:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-using-javascript-php-by-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Upload file using JavaScript and PHP\",\"datePublished\":\"2016-02-14T18:44:25+00:00\",\"dateModified\":\"2016-04-22T17:12:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/\"},\"wordCount\":286,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/upload-file-using-javascript-php-by-codexworld.png\",\"keywords\":[\"File Upload\",\"JavaScript\",\"PHP\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/\",\"name\":\"Upload file using JavaScript and PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/upload-file-using-javascript-php-by-codexworld.png\",\"datePublished\":\"2016-02-14T18:44:25+00:00\",\"dateModified\":\"2016-04-22T17:12:05+00:00\",\"description\":\"Upload file without page refresh using JavaScript and PHP \u2013 Learn how to upload file using JavaScript and PHP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/upload-file-using-javascript-php-by-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/upload-file-using-javascript-php-by-codexworld.png\",\"width\":1366,\"height\":768,\"caption\":\"upload-file-using-javascript-php-by-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/upload-file-using-javascript-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Upload file using JavaScript and PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Upload file using JavaScript and PHP - CodexWorld","description":"Upload file without page refresh using JavaScript and PHP \u2013 Learn how to upload file using JavaScript and PHP.","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.codexworld.com\/upload-file-using-javascript-php\/","og_locale":"en_US","og_type":"article","og_title":"Upload file using JavaScript and PHP - CodexWorld","og_description":"Upload file without page refresh using JavaScript and PHP \u2013 Learn how to upload file using JavaScript and PHP.","og_url":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2016-02-14T18:44:25+00:00","article_modified_time":"2016-04-22T17:12:05+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-using-javascript-php-by-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Upload file using JavaScript and PHP","datePublished":"2016-02-14T18:44:25+00:00","dateModified":"2016-04-22T17:12:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/"},"wordCount":286,"commentCount":2,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-using-javascript-php-by-codexworld.png","keywords":["File Upload","JavaScript","PHP"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/","url":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/","name":"Upload file using JavaScript and PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-using-javascript-php-by-codexworld.png","datePublished":"2016-02-14T18:44:25+00:00","dateModified":"2016-04-22T17:12:05+00:00","description":"Upload file without page refresh using JavaScript and PHP \u2013 Learn how to upload file using JavaScript and PHP.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-using-javascript-php-by-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-using-javascript-php-by-codexworld.png","width":1366,"height":768,"caption":"upload-file-using-javascript-php-by-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/upload-file-using-javascript-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Upload file using JavaScript and PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/02\/upload-file-using-javascript-php-by-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-kd","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=1253"}],"version-history":[{"count":5,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1253\/revisions"}],"predecessor-version":[{"id":1261,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1253\/revisions\/1261"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/1258"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=1253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=1253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=1253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}