繁体   English   中英

如何通过 HTML 格式的服务器上的网页将文件上传到我的 Web 服务器?

[英]How do I Upload Files to my Web Server Through a Webpage on the Server in HTML?

我想将文件上传到我的 Web 服务器,但我希望能够通过我服务器上的网页进行上传,以便任何人都可以将文件上传到我的服务器上。 我宁愿只使用 HTML5 和 JavaScript。

我感谢任何帮助,

格里芬

试试这个……这至少会让你开始。 仍未完成,我们无法为您完成所有工作;-)。 然后你可能想要进入 PHP/.NET 或其他进行实际上传。

<!DOCTYPE html>
<html>
<body onload="myFunction()">

<input type="file" id="myFile" multiple size="50" onchange="myFunction()">

<p id="demo"></p>

<script>
function myFunction(){
    var x = document.getElementById("myFile");
    var txt = "";
    if ('files' in x) {
        if (x.files.length == 0) {
            txt = "Select one or more files.";
        } else {
            for (var i = 0; i < x.files.length; i++) {
                txt += "<br><strong>" + (i+1) + ". file</strong><br>";
                var file = x.files[i];
                if ('name' in file) {
                    txt += "name: " + file.name + "<br>";
                }
                if ('size' in file) {
                    txt += "size: " + file.size + " bytes <br>";
                }
            }
        }
    } 
    else {
        if (x.value == "") {
            txt += "Select one or more files.";
        } else {
            txt += "The files property is not supported by your browser!";
            txt  += "<br>The path of the selected file: " + x.value; // If the browser does not support the files property, it will return the path of the selected file instead. 
        }
    }
    document.getElementById("demo").innerHTML = txt;
}
</script>

<p><strong>Tip:</strong> Use the Control or the Shift key to select multiple files.</p>

</body>
</html>

参考: W3School (2017 年 12 月 19 日)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM