如何使用PHP来保存一个base64德$ C $光盘镜像文件系统? [英] How to save a base64 decoded image in the filesystem using php?
本文介绍了如何使用PHP来保存一个base64德$ C $光盘镜像文件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是通过一个POST请求我的web服务获得一个base64连接codeD JPEG字符串。
我要脱code,并将其保存在文件系统中。
我怎样才能做到这一点使用PHP 5.3。
我能够成功地去code。使用base64_de code函数的数据。
I am getting a base64 encoded JPEG string via a POST request to my web service. I want to decode it and save it in the filesystem. How can I achieve this using PHP 5.3. I am able to successfully decode the data using the base64_decode function.
我怎么可以这样去codeD字符串保存为服务器中的JPEG图像?
How can I save this decoded string as a JPEG image in the server?
在此先感谢。
推荐答案
如果您确信形象将永远是JPG格式,那么你可以简单地使用:的的file_put_contents();
If you are sure the image will always be jpg then you can simply use: file_put_contents();
<?php
$decoded=base64_decode($encodedString);
file_put_contents('newImage.JPG',$decoded);
//leave it to you to randomize the filename.
?>
这篇关于如何使用PHP来保存一个base64德$ C $光盘镜像文件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文