简体   繁体   中英

Upload base64 string image

I have a plugin which crops my image and sends back a base64 data that looks like this: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ... . How can I upload this returned image via file upload field in my form to my server?

在此处输入图片说明

PS: In short I want to automaticly add returned image to my file input field of my form.

The same way you upload any other string to your server. The fact that the string is Base64 doesn't change anything.

You can put it in an <input type="hidden"> , then use PHP code to decode the Base64 and save the bytes somewhere.

使用此代码

$image =chunk_split( base64_encode(file_get_contents($_FILES['image_name']['tmp_name'])));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM