{"id":2106,"date":"2017-01-23T17:36:41","date_gmt":"2017-01-23T17:36:41","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=2106"},"modified":"2022-07-15T09:31:30","modified_gmt":"2022-07-15T09:31:30","slug":"ajax-file-upload-using-jquery-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/","title":{"rendered":"Ajax File Upload using jQuery and PHP"},"content":{"rendered":"<p>The easiest way to upload files in the web application is to use server-side code. The file upload functionality can be implemented with minimal lines of code in the server-side script. In the previous tutorial, we discussed a simple method to <a href=\"http:\/\/www.codexworld.com\/php-file-upload\/\">upload files in PHP<\/a>.  Today we\u2019ll build a simple Ajax file upload script with jQuery and PHP. The main purpose of the <b>Ajax file upload<\/b> functionality is to allow the user to upload files to the server without page refresh.<\/p>\n<p>There are various jQuery plugins are available to upload files or images without page refresh. But if you want to learn the Ajax file upload process and make your own Ajax file upload script, this step-by-step tutorial will help you a lot.<\/p>\n<p>Here we\u2019ll show how you can upload files to the server without page refresh using jQuery, Ajax, and PHP. Using our simple <b>Ajax file upload script<\/b>, you can easily implement file upload functionality without using any 3rd party plugin.<\/p>\n<h2>HTML Code<\/h2>\n<p>Define some HTML elements to display the file uploader container. The user can select a file to upload by clicking on this container element.<\/p>\n<pre style=\"color: rgb(95, 94, 78);\"><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">form<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"dropBox\"<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>Select file to upload<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"file\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"fileInput\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"fileInput\"<\/span> \/&gt;<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">form<\/span>&gt;<\/span><\/pre>\n<h2>CSS Code<\/h2>\n<p>Define CSS to make the file uploader box look good and hide the default file select input.<\/p>\n<pre style=\"color: rgb(0, 0, 0);\"><span class=\"hljs-selector-id\" style=\"color: green;\">#dropBox<\/span>{\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">border<\/span>: <span class=\"hljs-number\" style=\"color: navy;\">3px<\/span> dashed <span class=\"hljs-number\" style=\"color: navy;\">#0087F7<\/span>;\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">border-radius<\/span>: <span class=\"hljs-number\" style=\"color: navy;\">5px<\/span>;\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">background<\/span>: <span class=\"hljs-number\" style=\"color: navy;\">#F3F4F5<\/span>;\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">cursor<\/span>: pointer;\r\n}\r\n<span class=\"hljs-selector-id\" style=\"color: green;\">#dropBox<\/span>{\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">min-height<\/span>: <span class=\"hljs-number\" style=\"color: navy;\">120px<\/span>;\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">padding<\/span>: <span class=\"hljs-number\" style=\"color: navy;\">35px<\/span>;\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">box-sizing<\/span>: border-box;\r\n}\r\n<span class=\"hljs-selector-id\" style=\"color: green;\">#dropBox<\/span> <span class=\"hljs-selector-tag\" style=\"color: olive;\">p<\/span>{\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">text-align<\/span>: center;\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">margin<\/span>: <span class=\"hljs-number\" style=\"color: navy;\">2em<\/span> <span class=\"hljs-number\" style=\"color: navy;\">0<\/span>;\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">font-size<\/span>: <span class=\"hljs-number\" style=\"color: navy;\">17px<\/span>;\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">font-weight<\/span>: bold;\r\n}\r\n<span class=\"hljs-selector-id\" style=\"color: green;\">#fileInput<\/span>{\r\n    <span class=\"hljs-attribute\" style=\"color: maroon;\">display<\/span>: none;\r\n}<\/pre>\n<h2>JavaScript Code<\/h2>\n<p>First, include the jQuery library that is used to initialize the Ajax request and handle the upload process at the client-side. <\/p>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">script<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.6.0\/jquery.min.js\"<\/span>&gt;<\/span><span class=\"undefined\"><\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">script<\/span>&gt;<\/span><\/pre>\n<p>The following JavaScript code handles the file upload process using Ajax.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Once the uploader element (<code>#dropBox<\/code>) is clicked, the file input field (<code>#fileInput<\/code>) is trigger using jQuery <code>click()<\/code> method.<\/li>\n<li>Call the upload handler function (fileUpload) to initialize the upload process.<\/li>\n<li>The <code>fileUpload()<\/code> function initialize the XMLHttpRequest to post the file data to the server-side script (<code>upload.php<\/code>).<\/li>\n<li>Use <code>allowedFileTypes<\/code> variable to specify the file types that are allowed to upload (For example, we have set images and PDF files as allowed file types.).<\/li>\n<li>Use <code>allowedFileSize<\/code> variable to set the maximum size of the file that can be uploaded (For example, we have set 1024KB\/1MB as the maximum file size.).<\/li>\n<\/ul>\n<pre style=\"color: rgb(95, 94, 78);\"><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">script<\/span>&gt;<\/span>\r\n<span style=\"color: rgb(110, 107, 94);\">$(<span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">function<\/span>(<span class=\"hljs-params\" style=\"color: rgb(182, 86, 17);\"><\/span>)<\/span>{\r\n    <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ File input field trigger when the HTML element is clicked<\/span>\r\n    $(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"#dropBox\"<\/span>).click(<span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">function<\/span>(<span class=\"hljs-params\" style=\"color: rgb(182, 86, 17);\"><\/span>)<\/span>{\r\n        $(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"#fileInput\"<\/span>).click();\r\n    });\r\n    \r\n    <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Prevent browsers from opening the file when its dragged and dropped<\/span>\r\n    $(<span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>).on(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'drop dragover'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">function<\/span> (<span class=\"hljs-params\" style=\"color: rgb(182, 86, 17);\">e<\/span>) <\/span>{\r\n        e.preventDefault();\r\n    });\r\n\r\n    <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Call a function to handle file upload on select file<\/span>\r\n    $(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'input[type=file]'<\/span>).on(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'change'<\/span>, fileUpload);\r\n});\r\n\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(102, 132, 225);\">fileUpload<\/span>(<span class=\"hljs-params\" style=\"color: rgb(182, 86, 17);\">event<\/span>)<\/span>{\r\n    <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Allowed file types<\/span>\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> allowedFileTypes = <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'image.*|application\/pdf'<\/span>; <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/text.*|image.*|application.*<\/span>\r\n\r\n    <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Allowed file size<\/span>\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> allowedFileSize = <span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">1024<\/span>; <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/in KB<\/span>\r\n\r\n    <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Notify user about the file upload status<\/span>\r\n    $(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"#dropBox\"<\/span>).html(event.target.value+<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\" uploading...\"<\/span>);\r\n    \r\n    <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Get selected file<\/span>\r\n    files = event.target.files;\r\n    \r\n    <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Form data check the above bullet for what it is  <\/span>\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> data = <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">new<\/span> FormData();                                   \r\n\r\n    <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ File data is presented as an array<\/span>\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">for<\/span> (<span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> i = <span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">0<\/span>; i &lt; files.length; i++) {\r\n        <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> file = files[i];\r\n        <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">if<\/span>(!file.type.match(allowedFileTypes)) {              \r\n            <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Check file type<\/span>\r\n            $(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"#dropBox\"<\/span>).html(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'&lt;p class=\"error\"&gt;File extension error! Please select the allowed file type only.&lt;\/p&gt;'<\/span>);\r\n        }<span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">else<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">if<\/span>(file.size &gt; (allowedFileSize*<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">1024<\/span>)){\r\n            <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Check file size (in bytes)<\/span>\r\n            $(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"#dropBox\"<\/span>).html(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'&lt;p class=\"error\"&gt;File size error! Sorry, the selected file size is larger than the allowed size (&gt;'<\/span>+allowedFileSize+<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'KB).&lt;\/p&gt;'<\/span>);\r\n        }<span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">else<\/span>{\r\n            <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Append the uploadable file to FormData object<\/span>\r\n            data.append(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'file'<\/span>, file, file.name);\r\n            \r\n            <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Create a new XMLHttpRequest<\/span>\r\n            <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> xhr = <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">new<\/span> XMLHttpRequest();     \r\n            \r\n            <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Post file data for upload<\/span>\r\n            xhr.open(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'POST'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'upload.php'<\/span>, <span class=\"hljs-literal\" style=\"color: rgb(182, 86, 17);\">true<\/span>);  \r\n            xhr.send(data);\r\n            xhr.onload = <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">function<\/span> (<span class=\"hljs-params\" style=\"color: rgb(182, 86, 17);\"><\/span>) <\/span>{\r\n                <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">\/\/ Get response and show the uploading status<\/span>\r\n                <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> response = <span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">JSON<\/span>.parse(xhr.responseText);\r\n                <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">if<\/span>(xhr.status === <span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">200<\/span> &amp;&amp; response.status == <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'ok'<\/span>){\r\n                    $(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"#dropBox\"<\/span>).html(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'&lt;p class=\"success\"&gt;File has been uploaded successfully. Click to upload another file.&lt;\/p&gt;'<\/span>);\r\n                }<span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">else<\/span> <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">if<\/span>(response.status == <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'type_err'<\/span>){\r\n                    $(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"#dropBox\"<\/span>).html(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'&lt;p class=\"error\"&gt;File extension error! Click to upload another file.&lt;\/p&gt;'<\/span>);\r\n                }<span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">else<\/span>{\r\n                    $(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"#dropBox\"<\/span>).html(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">'&lt;p class=\"error\"&gt;Something went wrong, please try again.&lt;\/p&gt;'<\/span>);\r\n                }\r\n            };\r\n        }\r\n    }\r\n}<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">script<\/span>&gt;<\/span><\/pre>\n<p>Once the user selects a file, the file data is submitted to the <code>upload.php<\/code> file for further processing with PHP.<\/p>\n<h2>Upload File to the Server using PHP (upload.php)<\/h2>\n<p>This <code>upload.php<\/code> file is loaded by the Ajax request to handle the file upload operations with PHP.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Retrieve file details from posted data using the <b>PHP $_FILES<\/b> method.<\/li>\n<li>Validate file type to check whether the selected file is allowed to upload.<\/li>\n<li>Upload file to the server using move_uploaded_file() function in PHP.<\/li>\n<li>Return response data in JSON format using json_encode() function.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #007700\">if(isset(<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">)&nbsp;==&nbsp;<\/span><span style=\"color: #0000BB\">true<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Generate&nbsp;unique&nbsp;file&nbsp;name <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$fileName&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">time<\/span><span style=\"color: #007700\">().<\/span><span style=\"color: #DD0000\">'_'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">basename<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_FILES<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">\"file\"<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">\"name\"<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;File&nbsp;upload&nbsp;path <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$targetDir&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\">$targetFilePath&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$targetDir&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$fileName<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Allow&nbsp;certain&nbsp;file&nbsp;formats <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$fileType&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">pathinfo<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$targetFilePath<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">PATHINFO_EXTENSION<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$allowTypes&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array(<\/span><span style=\"color: #DD0000\">'jpg'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'png'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'jpeg'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'gif'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'pdf'<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">in_array<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$fileType<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$allowTypes<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Upload&nbsp;file&nbsp;to&nbsp;server <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">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\">\"file\"<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">\"tmp_name\"<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$targetFilePath<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Insert&nbsp;file&nbsp;data&nbsp;into&nbsp;the&nbsp;database&nbsp;if&nbsp;needed <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/........ <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Success&nbsp;response <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$response<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #DD0000\">'ok'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$response<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #DD0000\">'err'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$response<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #DD0000\">'type_err'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Render&nbsp;response&nbsp;data&nbsp;in&nbsp;JSON&nbsp;format <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">json_encode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$response<\/span><span style=\"color: #007700\">); <br \/>}<\/span><\/pre>\n<h2>Conclusion<\/h2>\n<p>In this example code, we tried to show the Ajax file upload process as simple as possible. You can enhance the functionality of this script with advanced features, like image preview, progress bar, etc. However, you can go through the following tutorials for other possible methods to upload files in PHP.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><a href=\"http:\/\/www.codexworld.com\/drag-and-drop-file-upload-using-dropzone-php\/\" target=\"_blank\" rel=\"noopener\">Drag and drop file upload using DropzoneJS and PHP<\/a><\/li>\n<li><a href=\"http:\/\/www.codexworld.com\/upload-file-using-javascript-php\/\" target=\"_blank\" rel=\"noopener\">Upload file using JavaScript and PHP<\/a><\/li>\n<li><a href=\"http:\/\/www.codexworld.com\/upload-multiple-images-using-jquery-ajax-php\/\" target=\"_blank\" rel=\"noopener\">Upload multiple images using jQuery, Ajax and PHP<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The easiest way to upload files in the web application is to use server-side code. The file upload functionality can be implemented with minimal lines of code in the server-side script. In the previous tutorial, <\/p>\n","protected":false},"author":1,"featured_media":5008,"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":[7],"tags":[28,56,16,14],"class_list":["post-2106","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ajax","tag-ajax","tag-file-upload","tag-jquery","tag-php","cat-7-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>Ajax File Upload using jQuery and PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"Ajax File Upload with jQuery and PHP - Learn how to upload files without page refresh using Ajax. Simple Ajax file upload script using jQuery 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\/ajax-file-upload-using-jquery-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ajax File Upload using jQuery and PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Ajax File Upload with jQuery and PHP - Learn how to upload files without page refresh using Ajax. Simple Ajax file upload script using jQuery and PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-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=\"2017-01-23T17:36:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-15T09:31:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/01\/ajax-file-upload-with-php-using-jquery-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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Ajax File Upload using jQuery and PHP\",\"datePublished\":\"2017-01-23T17:36:41+00:00\",\"dateModified\":\"2022-07-15T09:31:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/\"},\"wordCount\":506,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2017\\\/01\\\/ajax-file-upload-with-php-using-jquery-codexworld.png\",\"keywords\":[\"Ajax\",\"File Upload\",\"jQuery\",\"PHP\"],\"articleSection\":[\"Ajax\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/\",\"name\":\"Ajax File Upload using jQuery and PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2017\\\/01\\\/ajax-file-upload-with-php-using-jquery-codexworld.png\",\"datePublished\":\"2017-01-23T17:36:41+00:00\",\"dateModified\":\"2022-07-15T09:31:30+00:00\",\"description\":\"Ajax File Upload with jQuery and PHP - Learn how to upload files without page refresh using Ajax. Simple Ajax file upload script using jQuery and PHP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2017\\\/01\\\/ajax-file-upload-with-php-using-jquery-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2017\\\/01\\\/ajax-file-upload-with-php-using-jquery-codexworld.png\",\"width\":1366,\"height\":768,\"caption\":\"ajax-file-upload-with-php-using-jquery-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/ajax-file-upload-using-jquery-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ajax File Upload using jQuery 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":"Ajax File Upload using jQuery and PHP - CodexWorld","description":"Ajax File Upload with jQuery and PHP - Learn how to upload files without page refresh using Ajax. Simple Ajax file upload script using jQuery 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\/ajax-file-upload-using-jquery-php\/","og_locale":"en_US","og_type":"article","og_title":"Ajax File Upload using jQuery and PHP - CodexWorld","og_description":"Ajax File Upload with jQuery and PHP - Learn how to upload files without page refresh using Ajax. Simple Ajax file upload script using jQuery and PHP.","og_url":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2017-01-23T17:36:41+00:00","article_modified_time":"2022-07-15T09:31:30+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/01\/ajax-file-upload-with-php-using-jquery-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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Ajax File Upload using jQuery and PHP","datePublished":"2017-01-23T17:36:41+00:00","dateModified":"2022-07-15T09:31:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/"},"wordCount":506,"commentCount":1,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/01\/ajax-file-upload-with-php-using-jquery-codexworld.png","keywords":["Ajax","File Upload","jQuery","PHP"],"articleSection":["Ajax"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/","url":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/","name":"Ajax File Upload using jQuery and PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/01\/ajax-file-upload-with-php-using-jquery-codexworld.png","datePublished":"2017-01-23T17:36:41+00:00","dateModified":"2022-07-15T09:31:30+00:00","description":"Ajax File Upload with jQuery and PHP - Learn how to upload files without page refresh using Ajax. Simple Ajax file upload script using jQuery and PHP.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/01\/ajax-file-upload-with-php-using-jquery-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/01\/ajax-file-upload-with-php-using-jquery-codexworld.png","width":1366,"height":768,"caption":"ajax-file-upload-with-php-using-jquery-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/ajax-file-upload-using-jquery-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Ajax File Upload using jQuery 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\/2017\/01\/ajax-file-upload-with-php-using-jquery-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-xY","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/2106","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=2106"}],"version-history":[{"count":7,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/2106\/revisions"}],"predecessor-version":[{"id":5007,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/2106\/revisions\/5007"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/5008"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=2106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=2106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=2106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}