Created
January 16, 2020 11:46
-
-
Save ahmedali5530/584417f6eb4d6acca7ac4ffd1809681f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$uploaded_ids = []; | |
//upload files and add into database | |
//$ids[] = $last_insert_id; | |
echo json_encode(['data' => $uploaded_ids]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!