---
title: "Ajax File Upload in PHP"  
description: "Ajax File Upload in PHP"  
author: "Andrell Daniels"  
published: 2013-01-09  
updated: 2019-03-31  
canonical: https://www.mindstick.com/articles/1112/ajax-file-upload-in-php  
category: "php"  
tags: ["php"]  
reading_time: 5 minutes  

---

# Ajax File Upload in PHP

Ever wanted to [upload files](https://www.mindstick.com/forum/159300/create-an-express-js-route-to-upload-files-to-the-server-using-multer-middleware) using AJAX like in [GMAIL](https://answers.mindstick.com/qa/94700/why-does-gmail-say-no-connection), without reloading the page? Now you can. Cross [browser](https://www.mindstick.com/articles/323165/top-10-fastest-internet-browsers-in-the-world) [method](https://www.mindstick.com/forum/166/webservice-method) to upload files using AJAX in only 1Kb of code.\

You need to create a form with file [fields](https://answers.mindstick.com/qa/96632/explain-about-relationships-and-look-up-fields-in-ms-access) you wish to upload and [define](https://yourviews.mindstick.com/audio/1110/lifestyles-choices-that-define-our-lives) “onsubmit” event. Look at the example below how to do that.

Tested in IE5.5+, FF1.0+.

##### CODE:-

```
<script src="webtoolkit.aim.js" type="text/javascript"><!--mce:0--></script>                <script type="text/javascript"><!--mce:1--></script> <form action="index.php" method="post"> <div><label>Name:</label><input name="form[name]" type="text" /></div> <div><label>File:</label><input name="form[file]" type="file" /></div><div><input type="submit" value="SUBMIT" /></div></form><hr /> <div># of submited forms: <span id="nr">0</span></div> <div>last submit response (generated by form action - index.php file):</div>SOURCE CODE FOE webtoolkit.aim.js/****  AJAX IFRAME METHOD (AIM)*  http://www.webtoolkit.info/***/ AIM = {                frame : function(c) {                                var n = 'f' + Math.floor(Math.random() * 99999);                                var d = document.createElement('DIV');                                d.innerHTML = '';                                document.body.appendChild(d);                                 var i = document.getElementById(n);                                if (c &amp;&amp; typeof(c.onComplete) == 'function') {                                                i.onComplete = c.onComplete;                                }                                 return n;                },                 form : function(f, name) {                                f.setAttribute('target', name);                },                 submit : function(f, c) {                                AIM.form(f, AIM.frame(c));                                if (c &amp;&amp; typeof(c.onStart) == 'function') {                                                return c.onStart();                                } else {                                                return true;                                }                },                loaded : function(id) {                                var i = document.getElementById(id);                                if (i.contentDocument) {                                                var d = i.contentDocument;                                } else if (i.contentWindow) {                                                var d = i.contentWindow.document;                                } else {                                                var d = window.frames[id].document;                                }                                if (d.location.href == "about:blank") {                                                return;                                }                                 if (typeof(i.onComplete) == 'function') {                                                i.onComplete(d.body.innerHTML);                                }                }}
```

[SOURCE CODE](https://www.mindstick.com/forum/23271/is-there-a-way-to-get-the-source-code-from-an-apk-file) FOR index.php

print_r($_REQUEST['form']);

---

Original Source: https://www.mindstick.com/articles/1112/ajax-file-upload-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
