I gave an image as a parameter to the file_get_content() function and received it as the output of a string. Now I want to do the opposite of this operation. What should I do?
Advertisement
Answer
You can write it back to an image file using file_put_contents
Example:
$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);
If you then look into your folder “images/”, there should be a new file called “test-new.png”