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
function isUploadSupported() { | |
if (navigator.userAgent.match(/(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Windows Phone (OS 7|8.0))|(XBLWP)|(ZuneWP)|(w(eb)?OSBrowser)|(webOS)|(Kindle\/(1.0|2.0|2.5|3.0))/)) { | |
return false; | |
} | |
var elem = document.createElement('input'); | |
elem.type = 'file'; | |
return !elem.disabled; | |
}; |
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
<input id="file" type="file" accept="image/*"> |
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
if (window.File && window.FileReader && window.FormData) { | |
var $inputField = $('#file'); | |
$inputField.on('change', function (e) { | |
var file = e.target.files[0]; | |
if (file) { | |
if (/^image\//i.test(file.type)) { | |
readFile(file); | |
} else { |
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
function readFile(file) { | |
var reader = new FileReader(); | |
reader.onloadend = function () { | |
processFile(reader.result, file.type); | |
} | |
reader.onerror = function () { | |
alert('There was an error reading the file!'); | |
} |
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
function sendFile(fileData) { | |
var formData = new FormData(); | |
formData.append('imageData', fileData); | |
$.ajax({ | |
type: 'POST', | |
url: '/your/upload/url', | |
data: formData, | |
contentType: false, |
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
function processFile(dataURL, fileType) { | |
var maxWidth = 800; | |
var maxHeight = 800; | |
var image = new Image(); | |
image.src = dataURL; | |
image.onload = function () { | |
var width = image.width; | |
var height = image.height; |