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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:38:44+00:00 2026-06-11T10:38:44+00:00

My code produces no errors on the console. When I click the upload button,

  • 0

My code produces no errors on the console. When I click the upload button, nothing happens. There is a post sent to itself, as instructed in the tutorial I used but the image is not uploaded to my folder and it is not displayed on my page. Barring the fact I know I should use jquery (I will make the transition once I get it to upload to the folder) what is wrong with my code?

<?php

if (!empty($_FILES)) {
    $name = $_FILES['file']['name'];

    if ($_FILES['file']['error'] == 0) {move_uploaded_file($_FILES['file']
            ['tmp_name'], "post_images/" . $name))} 
}

?>



<script type="text/javascript">

var handleUpload = function (event) {
event.preventDefault();
event.stopPropagation();

var fileInput = document.getElementById('file');
var data = new FormData();  
data.append('file', fileInput.files[1]);    
var request = new XMLHttpRequest();
request.upload.addEventListener('progress', function(event){
    if (event.lengthComputable) 
    {
    var percent = event.loaded / event.total;
    var progress = document.getElementById('upload_progress');
    while(progress.hasChildNodes()) {
        progress.removeChild(progress.firstChild);          
    }   

progress.appendChild(document.createTextNode(Math.round(percent * 100) + 
    '%'));          

}

});

request.upload.addEventListener('load',function(event) {
document.getElementById('upload_progress').style.display = 'none';
});

request.upload.addEventListener('error', function(event) {
alert('Upload failed');
});

request.open('POST', 'upload.php');
request.setRequestHeader('Cache-Control', 'no-cache');
document.getElementById('upload_progress').style.display = 'block';
request.send(data); 

};


window.addEventListener('load', function(event) {
var submit = document.getElementById('submit');
submit.addEventListener('click', handleUpload);
});

</script>


<div id="uploaded">

<?php

if (!empty($name)) {

echo '<img src="post_images/' . $name . '" width="100" height="100" />';    

}

?>

</div>

<div id="upload_progress"></div>

<div>

<form action="" method="post" enctype="multipart/form-data">

<div>

    <input type="file" id="file" name="file" />
    <input type="submit" id="submit" value="upload" />

</div>

</form>

</div>
  • 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-11T10:38:45+00:00Added an answer on June 11, 2026 at 10:38 am

    There is only one file in a non- multiple file input element, fileInput.files[1] attempts to use the second file.

    data.append('file', fileInput.files[0]);    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this code produces 17 error C2995: function template has already been defined; there was
This code works as expected (does nothing, even doesn't produce warning/errors): l = lambda
This is my code: $myDiv = $('<div>1</div>'); $myDiv.each(function () { console.log(this.html()); }); It produces
The code below produces an error saying that my input string was not in
The following code produces no suitable constructor found error. I am unable to figure
Following code produces a nested array as a result for keys containing three items:
This code produces a different output in Python 2 and Python 3 . class
This code produces the result as 56. function x ($y) { function y ($z)
This code produces a mess... What am I doing wrong? cell=$(<td>); if(normal.exam_type==Exam_Boolean) { var
The following code produces wrong and inconsistent output with gcc (4.1.2 20080704) but correct

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.