我有一个脚本,可以获取文件的内容并使用 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";
?>
但不起作用。
这解决了我的问题。这两个函数不能很好地结合在一起,所以我将 file_get_contents 与 base64_decode 分开
<?php
$targetPath="D:/timekeeping/logs/94-20160908.dat";
$data = file_get_contents($targetPath);
$content= base64_decode($data);
$file = fopen($targetPath, 'w');
fwrite($file, $content);
fclose($file);
echo "done";
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)