我想尝试将图像转换为二进制。
我在网上找到了一个脚本,但它不起作用。
有人能告诉我为什么吗?
<?php
$image="image003.jpg";
$data = fopen ($image, 'rb');
$size=filesize ($image);
$contents= fread ($fd, $size);
fclose ($fd);
$encoded= base64_encode($contents);
echo $encoded;
?>
第 8 行和第 9 行出现错误
Warning: fread() expects parameter 1 to be resource
和
Warning: fclose() expects parameter 1 to be resource,
最佳答案
使用$data
代替$fd
$data = fopen ($image, 'rb');
$size=filesize ($image);
$contents= fread ($data, $size);
fclose ($data);
关于PHP将图像转换为二进制文件测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35216960/