Skip to content

Instantly share code, notes, and snippets.

@ahmedali5530
Created January 16, 2020 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedali5530/584417f6eb4d6acca7ac4ffd1809681f to your computer and use it in GitHub Desktop.
Save ahmedali5530/584417f6eb4d6acca7ac4ffd1809681f to your computer and use it in GitHub Desktop.
<div class="uploaded-files"></div>
<div id="imagesContainer" class="row"></div>
<button type="button" id="bSave" class="btn btn-info">Load Images</button>
<script>
$('#bSave').click(function(e) {
var images = $('iframe').contents().find('.modal-body').find('img');
if(images.length == 0){
alert('No Images found, please scan some images first.');
return false;
}
$('#imagesContainer').empty();
images.each(function(index, image){
$('#imagesContainer').append(`
<div class="col-md-12"><img src="${$(image).attr('src')}" class="thumbnail img-responsive"></div>
`);
var currentImageSrcString = $(image).attr('src');
var filename = 'random_name.png';
fetch(currentImageSrcString)
.then(res => res.blob())
.then(blob => {
const file = new File([blob], filename, {
type: 'image/png'
});
var fd = new FormData();
fd.append("photos", file);
$.ajax({
type: "POST",
url: 'upload.php',
data: fd,
processData: false,
contentType: false,
cache: false,
success: (response) => {
response.data.forEach(f => {
$('.uploaded-files').append(`
<input type="hidden" name="files[]" value="${f}">
`);
});
},
error: function (xhr, status, error) {
alert(xhr.responseText);
}
});
});
});
});
</script>
<?php
$uploaded_ids = [];
//upload files and add into database
//$ids[] = $last_insert_id;
echo json_encode(['data' => $uploaded_ids]);
@kamidehlvi
Copy link

AOA!
I am working on a twain based web application, I see your code to get connected with twain and scan document. please share how can it work toolset and hardware requirements to produce a demo on my pc.

@ahmedali5530
Copy link
Author

  1. install this extension first in chrome and install software which this extension offers https://chrome.google.com/webstore/detail/twian-scanner/pnamophecpodffkldpbpjiknnealolcm?hl=en
  2. open the twain_scanner.html file in browser
  3. Click on extension icon, choose one item from dropdown and scan a document
  4. After scanning a box will open with scanned pages (click on them to remove or just close the box)
  5. Then click on load Images button it will load the images into your web page, also it will upload them on your server and upload.php will return the ids, you then use those ids in your form to attach them with your inputs.

@wowfoot
Copy link

wowfoot commented Oct 29, 2020

After scanning, no box opened.
many times tried, but no box opened
Does the plugin have debug option of file saving or log ?
========twain.log ===================================
TWAIN_32.DLL - MESSAGE - CTWTRACE--CONTROL, IDENTITY, OPENDS
TWAIN_32.DLL - MESSAGE - CTWTRACE--CONTROL, USERINTERFACE, ENABLEDS
TWAIN_32.DLL - MESSAGE - CTWTRACE--CONTROL, [ 0000 ], XFERREADY
TWAIN_32.DLL - MESSAGE - CTWTRACE--CAPABILITY, GETCURRENT, XFERMECH
TWAIN_32.DLL - MESSAGE - CTWTRACE--IMAGE, IMAGENATIVEXFER, GET
TWAIN_32.DLL - MESSAGE - CTWTRACE--CONTROL, PENDINGXFERS, ENDXFER
TWAIN_32.DLL - MESSAGE - CTWTRACE--CONTROL, USERINTERFACE, DISABLEDS

@ahmedali5530
Copy link
Author

I don't know much about the extension, i only added the method for saving multiple images with the help of extension.

@kamidehlvi
Copy link

  1. install this extension first in chrome and install software which this extension offers https://chrome.google.com/webstore/detail/twian-scanner/pnamophecpodffkldpbpjiknnealolcm?hl=en
  2. open the twain_scanner.html file in browser
  3. Click on extension icon, choose one item from dropdown and scan a document
  4. After scanning a box will open with scanned pages (click on them to remove or just close the box)
  5. Then click on load Images button it will load the images into your web page, also it will upload them on your server and upload.php will return the ids, you then use those ids in your form to attach them with your inputs.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment