質問編集履歴
1
ドラッグ&ドロップの部分の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -97,3 +97,473 @@
|
|
97
97
|
ご教授いただければ幸いです。
|
98
98
|
|
99
99
|
以上、宜しくお願い致します。
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
【追記】
|
106
|
+
|
107
|
+
ドラッグ&ドロップする機能の部分を記載します。
|
108
|
+
|
109
|
+
長くなりますがご了承ください。
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
簡単に言ってしまうとこの2つを上手く融合したいのですが、うまくいかないということです。
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
--------------------------------------
|
118
|
+
|
119
|
+
<!DOCTYPE html>
|
120
|
+
|
121
|
+
<html>
|
122
|
+
|
123
|
+
<head>
|
124
|
+
|
125
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
|
126
|
+
|
127
|
+
<style>
|
128
|
+
|
129
|
+
#dragandrophandler
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
border:2px dotted #0B85A1;
|
134
|
+
|
135
|
+
width:500px;
|
136
|
+
|
137
|
+
height:300px;
|
138
|
+
|
139
|
+
color:#92AAB0;
|
140
|
+
|
141
|
+
text-align:center;
|
142
|
+
|
143
|
+
vertical-align:middle;
|
144
|
+
|
145
|
+
padding:10px 10px 10 10px;
|
146
|
+
|
147
|
+
margin: 0 auto;
|
148
|
+
|
149
|
+
font-size:200%;
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
.progressBar {
|
154
|
+
|
155
|
+
width: 200px;
|
156
|
+
|
157
|
+
height: 22px;
|
158
|
+
|
159
|
+
border: 1px solid #ddd;
|
160
|
+
|
161
|
+
border-radius: 5px;
|
162
|
+
|
163
|
+
overflow: hidden;
|
164
|
+
|
165
|
+
display:inline-block;
|
166
|
+
|
167
|
+
margin:0px 10px 5px 5px;
|
168
|
+
|
169
|
+
vertical-align:top;
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
.progressBar div {
|
176
|
+
|
177
|
+
height: 100%;
|
178
|
+
|
179
|
+
color: #fff;
|
180
|
+
|
181
|
+
text-align: right;
|
182
|
+
|
183
|
+
line-height: 22px; /* same as #progressBar height if we want text middle aligned */
|
184
|
+
|
185
|
+
width: 0;
|
186
|
+
|
187
|
+
background-color: #0ba1b5; border-radius: 3px;
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
.statusbar
|
192
|
+
|
193
|
+
{
|
194
|
+
|
195
|
+
border-top:1px solid #A9CCD1;
|
196
|
+
|
197
|
+
min-height:25px;
|
198
|
+
|
199
|
+
width:700px;
|
200
|
+
|
201
|
+
padding:10px 10px 0px 10px;
|
202
|
+
|
203
|
+
vertical-align:top;
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
.statusbar:nth-child(odd){
|
208
|
+
|
209
|
+
background:#EBEFF0;
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
.filename
|
214
|
+
|
215
|
+
{
|
216
|
+
|
217
|
+
display:inline-block;
|
218
|
+
|
219
|
+
vertical-align:top;
|
220
|
+
|
221
|
+
width:250px;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
.filesize
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
display:inline-block;
|
230
|
+
|
231
|
+
vertical-align:top;
|
232
|
+
|
233
|
+
color:#30693D;
|
234
|
+
|
235
|
+
width:100px;
|
236
|
+
|
237
|
+
margin-left:10px;
|
238
|
+
|
239
|
+
margin-right:5px;
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
.abort{
|
244
|
+
|
245
|
+
background-color:#A8352F;
|
246
|
+
|
247
|
+
-moz-border-radius:4px;
|
248
|
+
|
249
|
+
-webkit-border-radius:4px;
|
250
|
+
|
251
|
+
border-radius:4px;display:inline-block;
|
252
|
+
|
253
|
+
color:#fff;
|
254
|
+
|
255
|
+
font-family:arial;font-size:13px;font-weight:normal;
|
256
|
+
|
257
|
+
padding:4px 15px;
|
258
|
+
|
259
|
+
cursor:pointer;
|
260
|
+
|
261
|
+
vertical-align:top
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
</style>
|
266
|
+
|
267
|
+
</head>
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
<body>
|
272
|
+
|
273
|
+
<div id="dragandrophandler">ここにドロップしてください。</div>
|
274
|
+
|
275
|
+
<br><br>
|
276
|
+
|
277
|
+
<div id="status1"></div>
|
278
|
+
|
279
|
+
<script>
|
280
|
+
|
281
|
+
function sendFileToServer(formData,status)
|
282
|
+
|
283
|
+
{
|
284
|
+
|
285
|
+
var uploadURL ="http://hayageek.com/examples/jquery/drag-drop-file-upload/upload.php"; //Upload URL
|
286
|
+
|
287
|
+
var extraData ={}; //Extra Data.
|
288
|
+
|
289
|
+
var jqXHR=$.ajax({
|
290
|
+
|
291
|
+
xhr: function() {
|
292
|
+
|
293
|
+
var xhrobj = $.ajaxSettings.xhr();
|
294
|
+
|
295
|
+
if (xhrobj.upload) {
|
296
|
+
|
297
|
+
xhrobj.upload.addEventListener('progress', function(event) {
|
298
|
+
|
299
|
+
var percent = 0;
|
300
|
+
|
301
|
+
var position = event.loaded || event.position;
|
302
|
+
|
303
|
+
var total = event.total;
|
304
|
+
|
305
|
+
if (event.lengthComputable) {
|
306
|
+
|
307
|
+
percent = Math.ceil(position / total * 100);
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
//Set progress
|
312
|
+
|
313
|
+
status.setProgress(percent);
|
314
|
+
|
315
|
+
}, false);
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
return xhrobj;
|
320
|
+
|
321
|
+
},
|
322
|
+
|
323
|
+
url: uploadURL,
|
324
|
+
|
325
|
+
type: "POST",
|
326
|
+
|
327
|
+
contentType:false,
|
328
|
+
|
329
|
+
processData: false,
|
330
|
+
|
331
|
+
cache: false,
|
332
|
+
|
333
|
+
data: formData,
|
334
|
+
|
335
|
+
success: function(data){
|
336
|
+
|
337
|
+
status.setProgress(100);
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
$("#status1").append("File upload Done<br>");
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
});
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
status.setAbort(jqXHR);
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
var rowCount=0;
|
356
|
+
|
357
|
+
function createStatusbar(obj)
|
358
|
+
|
359
|
+
{
|
360
|
+
|
361
|
+
rowCount++;
|
362
|
+
|
363
|
+
var row="odd";
|
364
|
+
|
365
|
+
if(rowCount %2 ==0) row ="even";
|
366
|
+
|
367
|
+
this.statusbar = $("<div class='statusbar "+row+"'></div>");
|
368
|
+
|
369
|
+
this.filename = $("<div class='filename'></div>").appendTo(this.statusbar);
|
370
|
+
|
371
|
+
this.size = $("<div class='filesize'></div>").appendTo(this.statusbar);
|
372
|
+
|
373
|
+
this.progressBar = $("<div class='progressBar'><div></div></div>").appendTo(this.statusbar);
|
374
|
+
|
375
|
+
this.abort = $("<div class='abort'>中断</div>").appendTo(this.statusbar);
|
376
|
+
|
377
|
+
obj.after(this.statusbar);
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
this.setFileNameSize = function(name,size)
|
382
|
+
|
383
|
+
{
|
384
|
+
|
385
|
+
var sizeStr="";
|
386
|
+
|
387
|
+
var sizeKB = size/1024;
|
388
|
+
|
389
|
+
if(parseInt(sizeKB) > 1024)
|
390
|
+
|
391
|
+
{
|
392
|
+
|
393
|
+
var sizeMB = sizeKB/1024;
|
394
|
+
|
395
|
+
sizeStr = sizeMB.toFixed(2)+" MB";
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
else
|
400
|
+
|
401
|
+
{
|
402
|
+
|
403
|
+
sizeStr = sizeKB.toFixed(2)+" KB";
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
this.filename.html(name);
|
410
|
+
|
411
|
+
this.size.html(sizeStr);
|
412
|
+
|
413
|
+
}
|
414
|
+
|
415
|
+
this.setProgress = function(progress)
|
416
|
+
|
417
|
+
{
|
418
|
+
|
419
|
+
var progressBarWidth =progress*this.progressBar.width()/ 100;
|
420
|
+
|
421
|
+
this.progressBar.find('div').animate({ width: progressBarWidth }, 10).html(progress + "% ");
|
422
|
+
|
423
|
+
if(parseInt(progress) >= 100)
|
424
|
+
|
425
|
+
{
|
426
|
+
|
427
|
+
this.abort.hide();
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
this.setAbort = function(jqxhr)
|
434
|
+
|
435
|
+
{
|
436
|
+
|
437
|
+
var sb = this.statusbar;
|
438
|
+
|
439
|
+
this.abort.click(function()
|
440
|
+
|
441
|
+
{
|
442
|
+
|
443
|
+
jqxhr.abort();
|
444
|
+
|
445
|
+
sb.hide();
|
446
|
+
|
447
|
+
});
|
448
|
+
|
449
|
+
}
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
function handleFileUpload(files,obj)
|
454
|
+
|
455
|
+
{
|
456
|
+
|
457
|
+
for (var i = 0; i < files.length; i++)
|
458
|
+
|
459
|
+
{
|
460
|
+
|
461
|
+
var fd = new FormData();
|
462
|
+
|
463
|
+
fd.append('file', files[i]);
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
var status = new createStatusbar(obj); //Using this we can set progress.
|
468
|
+
|
469
|
+
status.setFileNameSize(files[i].name,files[i].size);
|
470
|
+
|
471
|
+
sendFileToServer(fd,status);
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
}
|
478
|
+
|
479
|
+
$(document).ready(function()
|
480
|
+
|
481
|
+
{
|
482
|
+
|
483
|
+
var obj = $("#dragandrophandler");
|
484
|
+
|
485
|
+
obj.on('dragenter', function (e)
|
486
|
+
|
487
|
+
{
|
488
|
+
|
489
|
+
e.stopPropagation();
|
490
|
+
|
491
|
+
e.preventDefault();
|
492
|
+
|
493
|
+
$(this).css('border', '2px solid #0B85A1');
|
494
|
+
|
495
|
+
});
|
496
|
+
|
497
|
+
obj.on('dragover', function (e)
|
498
|
+
|
499
|
+
{
|
500
|
+
|
501
|
+
e.stopPropagation();
|
502
|
+
|
503
|
+
e.preventDefault();
|
504
|
+
|
505
|
+
});
|
506
|
+
|
507
|
+
obj.on('drop', function (e)
|
508
|
+
|
509
|
+
{
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
$(this).css('border', '2px dotted #0B85A1');
|
514
|
+
|
515
|
+
e.preventDefault();
|
516
|
+
|
517
|
+
var files = e.originalEvent.dataTransfer.files;
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
//We need to send dropped files to Server
|
522
|
+
|
523
|
+
handleFileUpload(files,obj);
|
524
|
+
|
525
|
+
});
|
526
|
+
|
527
|
+
$(document).on('dragenter', function (e)
|
528
|
+
|
529
|
+
{
|
530
|
+
|
531
|
+
e.stopPropagation();
|
532
|
+
|
533
|
+
e.preventDefault();
|
534
|
+
|
535
|
+
});
|
536
|
+
|
537
|
+
$(document).on('dragover', function (e)
|
538
|
+
|
539
|
+
{
|
540
|
+
|
541
|
+
e.stopPropagation();
|
542
|
+
|
543
|
+
e.preventDefault();
|
544
|
+
|
545
|
+
obj.css('border', '2px dotted #0B85A1');
|
546
|
+
|
547
|
+
});
|
548
|
+
|
549
|
+
$(document).on('drop', function (e)
|
550
|
+
|
551
|
+
{
|
552
|
+
|
553
|
+
e.stopPropagation();
|
554
|
+
|
555
|
+
e.preventDefault();
|
556
|
+
|
557
|
+
});
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
});
|
562
|
+
|
563
|
+
</script>
|
564
|
+
|
565
|
+
</body>
|
566
|
+
|
567
|
+
</html>
|
568
|
+
|
569
|
+
------------------------------------------------
|