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

  • Home
  • SEARCH
  • 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 9055517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:58:19+00:00 2026-06-16T13:58:19+00:00

I have two image upload options one for icon and another for image, i

  • 0

I have two image upload options one for icon and another for image, i have made a custom ajax image upload function in jquery, which send values to php for processing. i am getting image upload to work properly i.e if icon is clicked only icon is uploaded and if image is clicked only image is uploded, my problem is i am getting both value as set in php which is causing error in not selected(icon or image) field.

my codes are:

html

<form name="change" enctype="multipart/form-data">
<input name="icon" type="file" />
<input name="image" type="file" />
</form>

<div id="icon"><img src="---" /></div>
<div id="image "><img src="---" /></div>
<div id="result"></div>

jquery(Ajax)

$('#icon img').click(function() {
    $('input[name=image ][type=file]').val(null);
    $('input[name=icon][type=file]').trigger('click');
});

$('#image img').click(function() {
    $('input[name=icon][type=file]').val(null);
    $('input[name=image ][type=file]').trigger('click');
});

$('input[name=icon], input[name=image ]').change(function() {
    change();
}); 


function change(){
var formData = new FormData($('form[name=change]')[0]);
formData.append("CustomField", "This is some extra data");
$.ajax({
    url: 'upload.php',
    type: 'POST',
    data: formData,
    success: (function(data){
    $('#result').html(data);
    }),
    cache: false,
    processData: false,
    contentType: false
});
}   

php

if(isset($_FILES['icon']) && !empty($_FILES['icon']) && $_FILES['icon'] !== ''){
echo 'icon set'.'<br />';
}
else{
echo 'icon not set'.'<br />';
}

if(isset($_FILES['image ']) && !empty($_FILES['image ']) && $_FILES['image '] !== ''){
echo 'image set'.'<br />';
}
else{
echo 'image not set'.'<br />';
}

If any one icon or image is selected to upload, I am getting result as.

icon set
image set

Please See and suggest what is causing error in php.

Thanks.

  • 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-06-16T13:58:20+00:00Added an answer on June 16, 2026 at 1:58 pm

    The keys “image” and “icon” are keys to arrays about the upload, so they are set, not empty, and not strings === “”. Try this:

    print_r($_FILES);
    

    And see if you get what you’re expecting. Also, could be formData object – Google for “php formData”

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

Sidebar

Related Questions

i have one image upload script which upload same image on two locations same
I have two models based in which one is related to another. class Contacts(BaseModel):
I have two columns in my NSOutlineView. One is a Text and image cell
I am building a form which would have image upload fields, but in way
I have a dialog box with two radio select options 'exist' and 'upload' and
Currently in my application I have two possible textboxes. One for a local image
im developing an application where i need to provide two upload file options one
I currently have an asp form that uses jquery for two elements: an image
I have use these code to upload two images in folder of the root
I have applied Two different Image Enhancement Algorithm on a particular Image and got

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.