【问题标题】:jquery cropbox how to upload imagejquerycropbox如何上传图片
【发布时间】:2018-06-06 17:11:13
【问题描述】:

有一个 jquery 插件https://github.com/acornejo/jquery-cropbox。 我只是不明白如何提取这个裁剪的图像并将其放入 $_FILES(php),所以我可以将它保存到我的服务器文件夹中。

【问题讨论】:

标签: 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 数组中。

【讨论】:

  • 如果有帮助,你能接受答案并投票吗?
猜你喜欢
  • 1970-01-01
  • 2012-07-16
  • 2010-11-22
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多