【发布时间】:2018-01-20 20:56:19
【问题描述】:
我试试这个参考:https://github.com/blueimp/JavaScript-Load-Image
我尝试这样:https://jsfiddle.net/oscar11/gazo3jc8/
我的代码 javascript 是这样的:
$(function () {
var result = $('#result')
var currentFile
function updateResults (img, data) {
var content
if (!(img.src || img instanceof HTMLCanvasElement)) {
content = $('<span>Loading image file failed</span>')
} else {
content = $('<a target="_blank">').append(img)
.attr('download', currentFile.name)
.attr('href', img.src || img.toDataURL())
var form = new FormData();
form.append('file', currentFile);
$.ajax({
url:'response_upload.php',
type:'POST',
data:form,
processData: false,
contentType: false,
success: function (response) {
console.log(response);
},
error: function () {
console.log(error)
},
});
}
result.children().replaceWith(content)
}
function displayImage (file, options) {
currentFile = file
if (!loadImage(
file,
updateResults,
options
)) {
result.children().replaceWith(
$('<span>' +
'Your browser does not support the URL or FileReader API.' +
'</span>')
)
}
}
function dropChangeHandler (e) {
e.preventDefault()
e = e.originalEvent
var target = e.dataTransfer || e.target
var file = target && target.files && target.files[0]
var options = {
maxWidth: result.width(),
canvas: true,
pixelRatio: window.devicePixelRatio,
downsamplingRatio: 0.5,
orientation: true
}
if (!file) {
return
}
displayImage(file, options)
}
// Hide URL/FileReader API requirement message in capable browsers:
if (window.createObjectURL || window.URL || window.webkitURL ||
window.FileReader) {
result.children().hide()
}
$('#file-input').on('change', dropChangeHandler)
})
如果我上传了图像,则保存在文件夹中的图像仍然不会使用其方向设置中的图像。我想上传图片的时候,文件夹中存储的图片是已经设置好方向的图片
似乎通过ajax发送的currentFile是未修改的currentfFile。如何获取修改后的currentFile?
【问题讨论】:
-
嗨,兄弟,我找到了解决方案,请参阅我的第二个答案。
-
@Novice,好的兄弟。非常感谢
标签: javascript php jquery image image-uploading