Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6944139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:14:51+00:00 2026-05-27T13:14:51+00:00

I want to upload an image without refreshing page. please help me for this

  • 0

I want to upload an image without refreshing page. please help me for this purpose. I find many thing but ever

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:14:52+00:00Added an answer on May 27, 2026 at 1:14 pm

    Complete Script :

    you need ajax to do it and here some code to work for u :

    ajaximage.php

    Contains PHP code.
    This script helps you to upload images into uploads folder.
    Image file name rename into timestamp+session_id.extention

    <?php
    
    include('db.php');
    
    session_start();
    
    $session_id='1'; // User session id
    
    $path = "uploads/";
    
    $valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
    
    if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
      $name = $_FILES['photoimg']['name'];
      $size = $_FILES['photoimg']['size'];
      if(strlen($name)) {
        list($txt, $ext) = explode(".", $name);
        if(in_array($ext,$valid_formats)) {
          if($size<(1024*1024)) // Image size max 1 MB
          {
            $actual_image_name = time().$session_id.".".$ext;
            $tmp = $_FILES['photoimg']['tmp_name'];
            
            if(move_uploaded_file($tmp, $path.$actual_image_name)) {
              mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'");
              echo "<img src='uploads/".$actual_image_name."' class='preview'>";
            }
            else
              echo "failed";
          }
          else
            echo "Image file size max 1 MB";
        }
        else
          echo "Invalid file format..";
      }
      else
        echo "Please select image..!";
      exit;
    }
       ?>
    

    index.php

    Contains simple PHP and HTML code.
    Here $session_id=1 means user id session value.

    <?php
    include('db.php');
    session_start();
    $session_id='1'; // User login session value
    ?>
    
    
    
    
    <form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'>
    
      Upload image <input type="file" name="photoimg" id="photoimg" />
    
    </form>
    
    <div id='preview'>
    </div>
    

    Sample database design for Users.

    Users
    Contains user details username, password, email, profile_image and profile_image_small etc.

    CREATE TABLE `users` (
    `uid` int(11) AUTO_INCREMENT PRIMARY KEY,
    `username` varchar(255) UNIQUE KEY,
    `password` varchar(100),
    `email` varchar(255) UNIQUE KEY,
    `profile_image` varchar(200),
    `profile_image_small` varchar(200),
    )
    

    Javascript Code

    $("#photoimg").on('change',function(){}) 
    // photoimg is the ID name of INPUT FILE tag and 
    
    $('#imageform').ajaxForm()
    //imageform is the ID name of FORM. While changing INPUT it calls FORM submit without refreshing page using ajaxForm() method.  
    
    <script type="text/javascript" src="http://ajax.googleapis.com/
    ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.form.js"></script>
    <script type="text/javascript">
      $(document).ready(function()
      {
        $('#photoimg').on('change', function()
        {
          $("#preview").html('');
          $("#preview").html('<img src="loader.gif" alt="Uploading...."/>');
          $("#imageform").ajaxForm(
          {
            target: '#preview'
          }).submit();
        });
      });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to upload image with the help of ajax or jQuery without page
Strange trouble I want to upload image via ajax which many plugin does but
I want to upload an image and show it without refresh. The method I
What I want I want to upload a file without reloading the page, also
I want to upload an image using a groovy on grails. My gsp page
I want the file input will automatic upload my image without enter any submit
how can i create a jQuery multiple image upload(upload without refresh page after choose
How to do the following: I want to have a link [upload image] which
Hallo I want to make an file upload. The script should take the image,
Let's say i have an image uploader script, i want to prevent the upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.