我有一个脚本,可以获取文件内容并使用base64进行编码。这个脚本运行良好:
<?php
$targetPath="D:/timekeeping/logs/94-20160908.dat";
$data = base64_encode(file_get_contents($targetPath));
$file = fopen($targetPath, 'w');
fwrite($file, $data);
fclose($file);
echo "file contents has been encoded";
?>
现在,我想把内容解码回原始值。我尝试了以下方法:
<?php
$targetPath="D:/timekeeping/logs/94-20160908.dat";
$data = base64_decode(file_get_contents($targetPath));
$file = fopen($targetPath, 'w');
fwrite($file, $data);
fclose($file);
echo "file contents has been decoded";
?>
但是不起作用。