Bladephp: Now with 7+ codeigniter, php, and laravel project 7+ php project From $18/Year From Rs. 1000/Year

How to upload image without refresh page using Ajax and PHP

by
Category:php
php ajax javascript jquery html
How to upload image without refresh page using Ajax and PHP

Are you looking for ajax file/image upload without refreshing page using ajax, Jquery and php. I had implemented this ajax form submitting using jquery.form plugin. You may also like How to Load Data From Database Without Page Refresh using Ajax, jQuery and PHP and How to Submit the Form Without Page Refresh using Ajax, jQuery and PHP.

HTML Code

<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>

jQuery Code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script> 
<script>
    $(document).ready(function() { 
        $('form').ajaxForm(function() { 
        }); 
    });
</script>

PHP Code

<?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();
    }
?>

0 Comments


Html code work in comment box


Related Post