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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:21:55+00:00 2026-06-14T13:21:55+00:00

How does xhr.upload.addEventListener(error, failed, false) differ from me having $success = move_uploaded_file($tmp_name, $name); if

  • 0

How does xhr.upload.addEventListener(“error”, failed, false) differ from me having $success = move_uploaded_file($tmp_name, $name); if $(success) { echo "0" } else { echo "1" }? Is this unnecessary redundancy?

function uploadPHP() {
    var xhr = new XMLHttpRequest();

    xhr.upload.addEventListener("progress", updateProgress, false);
    xhr.upload.addEventListener("load", complete, false);
    xhr.upload.addEventListener("error", failed, false);
    xhr.upload.addEventListener("abort", cancelled, false);

    var foo = document.getElementById("uploadScreen");
    var form = document.getElementById("uploadForm");
    var percentComplete;
    var index;

    xhr.onreadystatechange = function () {
        if (xhr.readyState == 1){
        }
--

    function cancelled() {
        //cancel
    }
}

localhost file_server # cat php/upload.php

<?php
//
//require_once('PhpConsole.php');
//PhpConsole::start();
$tmp_name = $_FILES['file1']['tmp_name'];
$path = "/trunk";
$name = $path . DIRECTORY_SEPARATOR . $_FILES['file1']['name'];
$success = move_uploaded_file($tmp_name, $name);
if ($success) {
echo "0";
} else {
    echo "1";
}
?>
  • 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-14T13:21:56+00:00Added an answer on June 14, 2026 at 1:21 pm

    "error" occurs if your request doesn’t get through, for example if it times out.

    Say you need to validate some data. If it is invalid, the "error" event won’t occur unless you throw an uncaught exception in your PHP. Instead, it will simply return some data that indicates the values were invalid, for example the string "0".

    In your given example, it is entirely possible for the move_uploaded_file to fail, yet the error handler won’t trigger because technically the request completed without untoward incident. The only indication you will have of the action you wanted to take having failed will be the "0" response.

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

Sidebar

Related Questions

In jQuery ajax function there is xhr option. Does someone know more details, usability
Is it possible in Dojo to create a widget programatically that does an xhr
Does jQuery.ajax({async: false}) still use the XMLHttpRequest object? If so, how is the request
I made a simple html to play with XHR, but get no response from
How does one return from a closure, without returning from the containing function? In
Does anyone know a way to get list of jQuery themes from http://jquery-ui.googlecode.com/svn/tags/1.8.23/themes/ ?
is anyone know why upload.onprogress does not work correctly if it's on separate function?
I have the following code which works: $(document).ready(function() { var xhr = false; func_two();
When I hear people talking about xmlhttprequest or XHR, does it basically mean an
i want jquery to take a JsonResult from my MVC controller but it does'nt

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.