簡體   English   中英

恢復內容 file_get_content() function

[英]Restore content file_get_content() function

我將圖像作為參數提供給 file_get_content() function 並將其作為字符串的 output 接收。 現在我想做與此操作相反的操作。 我應該怎么辦?

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

使用 base64 和file_put_contents處理圖像

在線 base64 圖像轉換為字符串編碼圖像

<?php

// Image as base64 truncated
$data = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAY8AAAFwCAYA...';

list($type, $data) = explode(';', $data);
list(, $data)      = explode(',', $data);
$data = base64_decode($data);

$image = 'image.png';

file_put_contents($image, $data);

echo "<img src='$file' alt='image' />";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM