Sie sind hier : sebastian1012.bplaced.net/ homepage-neu / Kurze-Scripte-und-Codeschnipsel / index.php

Zurück


Der Quellcode dazu


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html>
<head>
    <title>File API</title>
    <style>
    body{
    font-family: 'Segoe UI';
    font-size: 12pt;
}

header h1{
    font-size:12pt;
    color: #fff;
    background-color: #1BA1E2;
    padding: 20px;

}
article
{
    width: 80%;
    margin:auto;
    margin-top:10px;
}


#result ul{
    list-style: none;
    margin-top:20px;
}

    #result ul li
    {
        border-bottom: 1px solid #ccc;
        margin-bottom: 10px;    
    }

    </style>
</head>
<body>
    <header>
        <h1>File API</h1>
    </header>
    <article>
        <label for="files">Select multiple files: </label>
        <input id="files" type="file" multiple/>
        <output id="result" />
    </article>
    <script>
    window.onload = function(){
        
    //Check File API support
    if(window.File && window.FileList)
    {
        var filesInput = document.getElementById("files");
        
        filesInput.addEventListener("change", function(event){
            
            var files = event.target.files; //It returns a FileList object
            var filesInfo = "";
            
            for(var i = 0; i< files.length; i++)
            {
                var file = files[i];
                
                filesInfo += "<li>Name: " + file.name + "</br>" + 
                             " Size: " + file.size + " bytes</br>" + 
                             " Type: " + file.type + "</br>" +
                             " Modified Date: " + file.lastModifiedDate + "</li>";
                
            }
                                   
            var output = document.getElementById("result");
            
            output.innerHTML =  "<ul>" +  filesInfo + "</ul>";
        
        });
    }
    else
    {
        console.log("Your browser does not support File API");
    }
}
    
    </script>
</body>
</html>