php - 恢复内容 file_get_content() 函数
问题描述
我将图像作为参数提供给 file_get_content() 函数,并将其作为字符串的输出接收。现在我想做与此操作相反的操作。我应该怎么办?
解决方案
您可以使用file_put_contents将其写回图像文件
例子:
$pathToImage = '/images/test.png';
$newFile = '/images/test-new.png';
// Get the contents of the image file
$imgString = file_get_contents($pathToImage);
// Write it back to an image
file_put_contents($newFile, $imgString);
如果你然后查看你的文件夹“images/”,应该有一个名为“test-new.png”的新文件
推荐阅读
- haskell - 如何将多态数据类型转换为单个元素列表
- powershell - PowerShell 工作流 - 挂起
- swift - 从 firebase(Swift) 中选择选定的数据
- php - 无法使用 PHP foreach 循环成功遍历目录中的 imagss
- firebase - 反应本机 Firebase 权限被拒绝
- sbt - sbt: play scala starter example build 失败
- node.js - 如何让 Webpack 和 Typescript 使用外部 node_module 文件夹?
- sql - 子选择 SQL Server 中的案例
- html - 输入文本颜色与空闲颜色不同
- javascript - 使用两个 jquery 下拉菜单进行依赖过滤