首页 > 解决方案 > 恢复内容 file_get_content() 函数

问题描述

我将图像作为参数提供给 file_get_content() 函数,并将其作为字符串的输出接收。现在我想做与此操作相反的操作。我应该怎么办?

标签: php

解决方案


您可以使用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”的新文件


推荐阅读