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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:20:21+00:00 2026-05-26T02:20:21+00:00

I am trying to upload an image file using ajax to the server. However,

  • 0

I am trying to upload an image file using ajax to the server. However, till now i have only transported data to the background php script using ajax. I haven’t done so with files.However, I am trying as follows:-

     <form id="imageUploadForm" action="profileThis.php" method="POST"
       enctype="multipart/formdata"> 

         <input  type="file" id="boozeImgFile" name="boozeImgFile" >  

         <input type="button" onclick="uploadImage()" value="Upload">

    </form>

And my ajax code is as follows

      $("imageUploadForm").request(
       {
         method:'post',

         parameters:{category:$("category").value, categoryId:$("categoryId").value, userId:

         $("userInSession").value, uploadImage:'true'}, 

         onComplete:function()
         {
           alert("successfully uploaded to profilethis.php");

         },

         onSuccess:function(ajax)
         {
           alert(ajax.responseText);      

          },

         onFailure:ajaxFailure,

         onException:ajaxFailure
      }); 

However, when I am trying to retrieve it in my background script using $filename=$_FILES["boozeImgFile"]["name"] its not working

My profileThis.php looks like this

       if(isset($_REQUEST['uploadImage']))
       { 
         $name=$_FILES["boozeImgFile"]["name"];        

         $tempName=$_FILES["boozeImgFile"]["tmp_name"];

         $size=$_FILES["boozeImgFile"]["size"];

         $type=$_FILES["boozeImgFile"]["type"];

         if(($type=="image/jpg"||$type=="image/jpeg"||$type=="image/pjpeg")&&         ($size>0&&$size<=4096000))
         {
        $userId=clearSpecialChars($_REQUEST['userId']);

                $tempName=$_FILES["boozeImgFile"]["tmp_name"];

            $category=clearSpecialChars($_REQUEST['category']);

            $categoryId=clearSpecialChars($_REQUEST['categoryId']);

               $name="img_".$userId."_".$filename;


               $rootDir="C:/xampp/htdocs";

               $dir="/boozeimg/".$category."/".$categoryId;

               $fullDirectory=$rootDir.$dir;

               $realPath=$dir."/".$name;

               $fullPath=$rootDir.$dir."/".$name;


       if(is_dir($fullDirectory))
       {
        move_uploaded_file($tempName, $fullPath);

       }
       else
       {
        mkdir($fullDirectory,0777,true);

        move_uploaded_file($tempName, $fullPath);

       }
     }

In profileThis.php the first line inside the if condition doesn’t reach, however the if condition by itself does reach

  • 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-26T02:20:21+00:00Added an answer on May 26, 2026 at 2:20 am

    Well the quick answer is you can’t. You can’t use AJAX to upload files. What you can do is have the target of a form be a hidden iframe and submit your form to that. It is essentially the same thing in result, but technically completely different. Most people still use the term ajax (including my forthcoming url), but it’s definitely not ajax. Here’s a link with a short tutorial:

    http://www.coursesweb.net/ajax/upload-images

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

Sidebar

Related Questions

I'm trying to upload an image from android to a PHP server by using
I am trying to upload an image to server using using XMLHttpRequest but fails.
Hi I am trying to upload image file using perl cgi-application. Not sure what
I'm trying to upload file, using XMLHTTPRequest, and sending this headers: Content-Type:multipart/form-data, boundary=xxxxxxxxx --xxxxxxxxx
I have been trying to use an ajax-style file upload component (like the dojox
I am trying to upload a file using jQuery ajax, but keep getting this
I'm trying to upload an image to my site through a form, however it's
i am trying to upload an image from a jsp page using servlet. but
I am trying to upload an image to the server. I hava a form
I am trying to upload a file or stream of data to our web

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.