【发布时间】:2015-03-03 19:47:28
【问题描述】:
我可以安全地假设使用以下 PHP 代码创建的 PNG 图像文件的大小(以字节为单位):
$f = fopen("newImageFile.png", 'w');
$content = base64_decode(substr($dataURL, strpos($dataURL, ',') + 1));
fwrite($f, $content);
$dataURL 是从 HTML 的 canves.toDataURL() 发布的,完全等于 strlen($content)?
【问题讨论】:
-
鉴于“strlen() returns the number of bytes rather than the number of characters in a string”,我认为这是查找数据长度的合理方法。我不确定文件大小会有什么不同,但我对此并不完全确定,所以我不会回答这个问题:) 不过我肯定会用“wb”打开你的文件,而不仅仅是“w”,因为您正在编写二进制数据。
-
谢谢。我真的不知道在写二进制数据时我应该使用“wb”模式。我刚刚重读了文档,谢谢。