Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use utf8;
- use CGI;
- use URI::Escape;
- use File::Basename;
- use File::Copy;
- use File::Path;
- use Encode;
- use FindBin;
- my $q = new CGI;
- my $files = $q->param('file');
- my $out = <<"EOM";
- Content-type: text/html
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <script src="http://code.jquery.com/jquery-1.12.4.js"></script>
- <script type="text/javascript">
- function PageLoad(e) {
- alert("hoge");
- var dropFrame = document.getElementById('DropFrame');
- dropFrame.addEventListener('dragover', onDragOver, false);
- dropFrame.addEventListener('drop', onDrop, false);
- }
- function onDragOver(e){
- e.preventDefault();
- }
- function onDrop(e) {
- e.stopPropagation();
- e.preventDefault();
- var files = e.dataTransfer.files;
- uploadFile(files[0]);
- }
- function uploadFile(file){
- var formData = new FormData();
- formData.append('file', file);
- $.ajax({
- async: true,
- type: 'POST',
- contentType: false,
- processData: false,
- url: 'dndtest.cgi',
- data: formData,
- dataType :'html'
- }).done(function(){});
- }
- </script>
- </head>
- <body>
- <div id="DropFrame" style="background-color:#b8deff;border:solid 1px #3470ff; width:360px; height:120px;">ここにファイルをドロップします。<br />$files</div>
- <script type="text/javascript">
- $(function(){
- PageLoad();
- });
- </script>
- </body>
- </html>
- EOM
- print(encode('UTF-8', $out)) or die($!);
- function drop(e) {
- e.stopPropagation();
- e.preventDefault();
- var files = e.dataTransfer.files;
- fup(files[0]);
- }
- function fup(file) {
- var formData = new FormData();
- formData.append('file', file);
- //javascriptだけなら
- // var up = new XMLHttpRequest();
- // up.open("POST", "f.php", true);
- // up.send(formData);
- //jqueryを使っているなら
- $.ajax({
- async: true,
- type: 'POST',
- contentType: false,
- processData: false,
- url: 'f.php',
- data: formData,
- dataType :'html'
- }).done(function(){});
- }
- $(function(){
- PageLoad();
- });
- var formData = new FormData();
- formData.append('file', file);
Add Comment
Please, Sign In to add comment