Guest User

Untitled

a guest
Jan 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use utf8;
  4. use CGI;
  5. use URI::Escape;
  6. use File::Basename;
  7. use File::Copy;
  8. use File::Path;
  9. use Encode;
  10. use FindBin;
  11.  
  12. my $q = new CGI;
  13. my $files = $q->param('file');
  14.  
  15. my $out = <<"EOM";
  16. Content-type: text/html
  17.  
  18. <?xml version="1.0" encoding="utf-8"?>
  19. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  20. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  21. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
  22. <head>
  23. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  24.  
  25. <script src="http://code.jquery.com/jquery-1.12.4.js"></script>
  26. <script type="text/javascript">
  27. function PageLoad(e) {
  28. alert("hoge");
  29. var dropFrame = document.getElementById('DropFrame');
  30. dropFrame.addEventListener('dragover', onDragOver, false);
  31. dropFrame.addEventListener('drop', onDrop, false);
  32. }
  33. function onDragOver(e){
  34. e.preventDefault();
  35. }
  36.  
  37. function onDrop(e) {
  38. e.stopPropagation();
  39. e.preventDefault();
  40.  
  41. var files = e.dataTransfer.files;
  42.  
  43. uploadFile(files[0]);
  44. }
  45. function uploadFile(file){
  46. var formData = new FormData();
  47. formData.append('file', file);
  48. $.ajax({
  49. async: true,
  50. type: 'POST',
  51. contentType: false,
  52. processData: false,
  53. url: 'dndtest.cgi',
  54. data: formData,
  55. dataType :'html'
  56. }).done(function(){});
  57. }
  58. </script>
  59. </head>
  60. <body>
  61. <div id="DropFrame" style="background-color:#b8deff;border:solid 1px #3470ff; width:360px; height:120px;">ここにファイルをドロップします。<br />$files</div>
  62. <script type="text/javascript">
  63. $(function(){
  64. PageLoad();
  65. });
  66. </script>
  67. </body>
  68. </html>
  69. EOM
  70. print(encode('UTF-8', $out)) or die($!);
  71.  
  72. function drop(e) {
  73. e.stopPropagation();
  74. e.preventDefault();
  75.  
  76. var files = e.dataTransfer.files;
  77.  
  78. fup(files[0]);
  79. }
  80. function fup(file) {
  81. var formData = new FormData();
  82. formData.append('file', file);
  83.  
  84. //javascriptだけなら
  85. // var up = new XMLHttpRequest();
  86. // up.open("POST", "f.php", true);
  87. // up.send(formData);
  88.  
  89. //jqueryを使っているなら
  90. $.ajax({
  91. async: true,
  92. type: 'POST',
  93. contentType: false,
  94. processData: false,
  95. url: 'f.php',
  96. data: formData,
  97. dataType :'html'
  98. }).done(function(){});
  99. }
  100.  
  101. $(function(){
  102. PageLoad();
  103. });
  104.  
  105. var formData = new FormData();
  106. formData.append('file', file);
Add Comment
Please, Sign In to add comment