我以二进制形式读取图片文件,为什么输出结果为乱码啊?

阿阿阿黄 2016-10-29 01:33:21
html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form name="form" method="post" action="index.php" enctype="multipart/form-data" >
<input name="cover" type="file" id="cover" size="10">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>


index.php:
<?php
$cover=$_POST['cover'];
if($_POST['Submit']==true){
$cover_type=strstr($cover, '.');
$arr=array('.jpg','.gif','.JPG','.GIF','.bmp','.BMP');
if(!in_array($cover_type, $arr)){
echo "<script>alert('no');</script>";
}else{
$cover=iconv("utf-8","gb2312",$cover);//字符串设置为utf-8
$fp=fopen($cover,"rb");//以二进制形式打开图片
$image=addslashes((fread($fp,filesize($cover))));
var_dump($image);//这里结果输出为乱码,而不是二进制数

}
}

?>
...全文
599 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿阿阿黄 2016-10-30
  • 打赏
  • 举报
回复
$cover有值,就是图片的路径
xuzuning 2016-10-29
  • 打赏
  • 举报
回复
$cover=$_POST['cover']; 你的 $cover 有值吗?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧