xhr.upload.addEventListener("error", failed, false) 与我有什么不同$success = move_uploaded_file($tmp_name, $name); if $(success) { echo "0" } else { echo "1" }
?这是不必要的冗余吗?
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";
}
?>