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 6473191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:26:11+00:00 2026-05-25T06:26:11+00:00

I am creating an AJAX PHP upload script, but I am having troubles. After

  • 0

I am creating an AJAX PHP upload script, but I am having troubles. After the user selects an image to upload, it will show in the div container that I specified in the javascript file (good). But, the moving the uploaded file does not seem to work, or at least I think that is what the problem is. I set the uploads/ folder to have permission of “777”.

Here is the JS file:

$(document).ready(function () {
  $("#upload-image-button").hide();

  var input = document.getElementById("images"),
    formdata = false;

  function showUploadedItem(source) {
    var list = document.getElementById("image-list"),
        li = document.createElement("li"),
        img = document.createElement("img");
    img.src = source;
    $("#topic-img-container").html(img);
  }  

  if (window.FormData) {
    formdata = new FormData();
    $("#upload-image-button").hide();
  }

  $("input[type='file']").live("change", function(event) {
    $("#response").html("Uploading...");
    var i = 0, len = this.files.length, img, reader, file;

    for (; i < len; i++) {
      file = this.files[i];

      if (!!file.type.match(/image.*/)) {
        if (window.FileReader) {
          reader = new FileReader();
          reader.onloadend = function (e) {
            showUploadedItem(e.target.result, file.fileName);
          };
          reader.readAsDataURL(file);
        }
        if (formdata) {
          formdata.append("images[]", file);
        }
      }
    }

    if (formdata) {
      $.ajax({
        url: "db/upload_image.php",
        type: "POST",
        data: formdata,
        processData: false,
        contentType: false,
        success: function (res) {
          document.getElementById("response").innerHTML = res;
        }
      });
    }
  }, false);
});

Here is the PHP file:

<?php
  foreach($_FILES["images"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
      print_r($_FILES);
      $name = $_FILES["images"]["name"][$key];
      move_uploaded_file($FILES["images"]["tmp_name"][$key], "uploads/" . $_FILES["images"]["name"][$key]);
      echo $FILES["images"]["tmp_name"][$key];
    }
  }

  echo "Success";
?>

It gets into the loop when there is no error. When I go to the upload folder, there are no new files. Any idea why this might be?

  • 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-25T06:26:12+00:00Added an answer on May 25, 2026 at 6:26 am

    You cannot upload files using AJAX. You need a helper Iframe that you send via a regular form-post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently creating a site(php,css,html,ajax,MySql) which will have heavy user usage of space(regarding
I am creating an AJAX application. When a user selects a button a new
I'm creating a simple ajax call to retrieve a list of user reviews. I
How do I start with creating a file upload mechanism that works via Ajax?
I'm reading a tutorial about creating a shoutbox with jquery, php and ajax. In
Feeling very proud of myself after creating a form with an AJAX submit, I
How would I go about creating an HTML/PHP/AJAX file uploader with a progress bar?
I'm creating a website which will require much AJAX functionality. At the moment I'm
I am creating a PHP/AJAX chat client. The application makes an AJAX request to
If I'm making an 'ajaxified' user interface with many ajax calls for creating, renaming,

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.