PHP - 从现场数据中保存 JPEG
PHP - Save JPEG from Field Data
我有一个表单,其中包含一个 <input type="text" name="imageData">
字段和 JPEG image
数据:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAEsKADAAQAAAABAAADhAAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZjs+EJ+/8AAEQgDhASwAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEA....
如何在 post 表格信息后使用 PHP
创建一个 JPG image
使用此数据?
谢谢
如果你得到 imageData
到 PHP 的内容,你可以拆分字符串(使用 base64,
,然后解码实际的 base64 字符串(使用 base64_decode), now you have the actual jpeg data, the only thing you need now is to save this data (you can do this using file_put_contents
:
$data = $_POST['imageData'];
$exploded = explode('base64,', $data);
if ($exploded) {
$base64_string = $exploded[1];
$image_binary_data = base64_decode($base64_string);
file_put_contents('new_image.jpg', $image_binary_data);
}
我有一个表单,其中包含一个 <input type="text" name="imageData">
字段和 JPEG image
数据:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAEsKADAAQAAAABAAADhAAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZjs+EJ+/8AAEQgDhASwAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEA....
如何在 post 表格信息后使用 PHP
创建一个 JPG image
使用此数据?
谢谢
如果你得到 imageData
到 PHP 的内容,你可以拆分字符串(使用 base64,
,然后解码实际的 base64 字符串(使用 base64_decode), now you have the actual jpeg data, the only thing you need now is to save this data (you can do this using file_put_contents
:
$data = $_POST['imageData'];
$exploded = explode('base64,', $data);
if ($exploded) {
$base64_string = $exploded[1];
$image_binary_data = base64_decode($base64_string);
file_put_contents('new_image.jpg', $image_binary_data);
}