[英]jquery cropbox how to upload image
There is a plugin for jquery https://github.com/acornejo/jquery-cropbox . 有一个jQuery插件https://github.com/acornejo/jquery-cropbox 。 I just don't understand how to extract this cropped image and put it into $_FILES(php), so I can save it to my server folder.
我只是不了解如何提取此裁剪的图像并将其放入$ _FILES(php),因此可以将其保存到服务器文件夹中。
You can do it by DATA property of the image. 您可以通过图像的DATA属性来实现。
To do the said process (loading a preview of the image file), HTML5's FileReader API. 要执行上述过程(加载图像文件的预览),请使用HTML5的FileReader API。
Using the FileReader API is actually simple, and it can be done like so: 实际上,使用FileReader API很简单,可以这样进行:
Javascript Java脚本
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);
You can place this code inside your onchange event handler, and I guess you won't be needing AJAX in here. 您可以将这段代码放在onchange事件处理程序中,我想您这里不需要AJAX。
Then when the form gets submitted, the image data can be obtained in its usual place, in the $_FILES array. 然后,当提交表单时,可以在其通常位置的$ _FILES数组中获取图像数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.