Upload Image Without Page Refresh Using Ajax,jQuery And PHP
Last Updated : Apr 15, 2022
In this tutorial we will show you how to upload image without page refresh using ajax,jQuery and PHP but before proceeding further you have to download jQuery and jQuery form plugin which is most important to upload image without page refresh.
You may also like drag and drop image upload using jQuery ajax and PHP.
To Upload Image Without Page Refresh It Takes Only One Step:-
- Make a PHP file and define markup and scripting
Step 1. Make a PHP file and define markup and scripting
We make a PHP file and save it with a name upload.php
<?php if(isset($_POST['submit_image'])) { $uploadfile=$_FILES["upload_file"]["tmp_name"]; $folder="images/"; move_uploaded_file($_FILES["upload_file"]["tmp_name"], "$folder".$_FILES["upload_file"]["name"]); exit(); } ?> <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.form.js"></script> <script> $(document).ready(function() { $('form').ajaxForm(function() { }); }); </script> </head> <body> <div id="wrapper"> <form action="" method="post" enctype="multipart/form-data"> <input type="file" id="upload_file" name="upload_file" /> <input type="submit" name='submit_image' value="Upload Image"/> </form> </div> </body> </html>
In this step first we create a form to upload image then we insert jquery and jquery form plugin to upload
image without page refresh then we use document.ready function to ready the ajaxform code to run whenever user clicks on submit button.
Whenever user clicks on submit button ajaxform will submit data or in our case upload image and prevents the page refresh.
And in our PHP code we simply get the image send by ajaxform and uploaded to our image directory.
You may also like Upload Image to Database and Server using HTML,PHP and MySQL
Thats all, this is how to upload image without page refresh using Ajax, jQuery and PHP. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.
Latest Tutorials
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery