I would like to create a mechanism to upload files to the server after dragging & dropping files using JavaScript and Perl.
"Upload multiple images in bulk by dragging and dropping using Ajax"
http://qiita.com/uda0922/items/4e22908ce2acb3a28f29
I tried to make it while looking at things like that, but it didn't work.No response.
Perl Affected Functions
subUploadFiles(){
my@files=$q->param('upload');
foreach my$file(@files){
my$tmp=$q->tmpFileName($file);
$file=basename($file);
my$path=".";
my$newfile="$path/$file";
copy($tmp,$newfile);
$newfile=decode('UTF-8', $newfile);
Uploaded $err.=$newfile."";
}
}
Form part
<form name="form" action="./sfs.cgi" method="POST" enctype="multipart/form-data">
<p>
<input type="file" name="upload" size="100" multiple/>
<button type="submit" name="submit" value="upload">Upload</button>
</p>
</form>
JavaScript
<script type="text/javascript">
// Hide area if File API is not supported
if(!window.File){
document.getElementById('image_upload_section').style.display="none";
}
// Suppresses the behavior of deploying files on a browser
function onDragonOver(event){
event.preventDefault();
}
// File property information read processing when dropped into the drop area
function onDrop(event){
// Suppresses the behavior of deploying files on a browser
event.preventDefault();
// Browse files properties for dropped files
var files = event.dataTransfer.files;
for (vari=0;i<files.length;i++) {
// Upload one at a time
imageFileUpload(files[i]);
}
}
// file upload
function imageFileUpload(f){
var formData = new FormData();
formData.append('image',f);
$.ajax({
type: 'POST',
contentType: false,
processData: false,
url: './sfs.cgi',
data —FormData,
dataType: 'json',
success:function(data){
alert("ok!");
}
});
}
</script>
I would appreciate it if you could let me know.
javascript html5 perl
Looking at the code, I think that even if you drag and drop a file, it will only open.
The code specified as a sample is like a program that POSTs files with Ajax, so you don't need a Form tag.
Please prepare a space for dropping files in DIV, etc., and set the event handler "ondragover="onDragOver(event)"ondrop="onDrop(event)" as shown in the sample for that area.
From what I see, I think this will work.
The reason is that the event handler is not configured to receive the event even if you drag and drop the file.
© 2024 OneMinuteCode. All rights reserved.