【问题标题】:jquery cropbox how to upload imagejquerycropbox如何上传图片
【发布时间】:2018-06-06 17:11:13
【问题描述】:
【问题讨论】:
-
“获取裁剪后的图像作为数据 URL 或二进制 blob 以将其上传到服务器”。他们的示例显示了下载...请参阅img.getDataURL(),您只需将其发布到服务器即可。也许read this.
-
标签:
javascript
php
image
file
【解决方案1】:
您可以通过图像的 DATA 属性来完成。
要执行上述过程(加载图像文件的预览),HTML5 的 FileReader API。
使用 FileReader API 其实很简单,可以这样做:
Javascript
var logo = document.getElementById("logo").files[0]; // will return a File object containing information about the selected file
// File validations here (you may want to make sure that the file is an image)
var reader = new FileReader();
reader.onload = function(data) {
// what you want to do once the File has been loaded
// you can use data.target.result here as an src for an img tag in order to display the uplaoded image
someImageElement.src = data.target.result; // assume you have an image element somewhere, or you may add it dynamically
}
reader.readAsDataURL(logo);
您可以将此代码放在 onchange 事件处理程序中,我猜您在这里不需要 AJAX。
然后当表单被提交时,图像数据就可以在它通常的位置获取,在 $_FILES 数组中。