-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadfile.html
151 lines (91 loc) · 3.59 KB
/
readfile.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<style>
.thumb {
height: 75px;
border: 1px solid #000;
margin: 10px 5px 0 0;
}
</style>
</head>
<body>
<input type="file" id="image" name="files[]" multiple />
<output id="list"></output>
<script>
var createStatement = "CREATE TABLE IF NOT EXISTS Images (id INTEGER PRIMARY KEY AUTOINCREMENT,image BLOB)";
var insertStatement = "INSERT INTO Images (image) VALUES (?)";
var selectStatement = "SELECT * FROM Images "
var db = openDatabase("Address", "1.0", "Address Book", 200000); // Open SQLite Database
var dataset;
var DataType;
function initDatabase() // Function Call When Page is ready.
{
try {
if (!window.openDatabase) // Check browser is supported SQLite or not.
{
alert('Databases are not supported in this browser.');
}
else {
createTable(); // If supported then call Function for create table in SQLite
}
}
catch (e) {
if (e == 2) {
// Version number mismatch.
console.log("Invalid database version.");
} else {
console.log("Unknown error " + e + ".");
}
return;
}
}
function createTable() // Function for Create Table in SQLite.
{
db.transaction(function (tx) { tx.executeSql(createStatement, [], onError); });
}
/* function insertRecord() // Get value from Input and insert record . Function Call when Save/Submit Button Click..
{
var imagetemp = r;
db.transaction(function (tx) { tx.executeSql(insertStatement, [imagetemp],onError); });
//tx.executeSql(SQL Query Statement,[ Parameters ] , Sucess Result Handler Function, Error Result Handler Function );
} */
$(document).ready(function () // Call function when page is ready for load..
{
$("body").fadeIn(2000); // Fede In Effect when Page Load..
initDatabase();
// $("#sub").click(insertRecord); // Register Event Listener when button click.
});
function onError(tx, error) // Function for Hendeling Error...
{
alert(error.message);
}
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<img class="thumb" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
var imagetemp =e.target.result;;
db.transaction(function (tx) { tx.executeSql(insertStatement, [imagetemp],onError); });
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('image').addEventListener('change' , handleFileSelect, false);
</script>
</body>
</html>