折腾了好几天了
for($m=0;$m<4;$m++){
if($_FILES['img'.($m+1)]['name']!=''){
$name=$_FILES['img'.($m+1)]['name'];
$type=$_FILES['img'.($m+1)]['type'];
$size=$_FILES['img'.($m+1)]['size'];
$tmp_name=$_FILES['img'.($m+1)]['tmp_name'];
$month=date('Ym');
$time0=substr(time(),-7);
$endnums=rand(1000,9999);
$thisname=explode(".",$name);
$basename=end($thisname);
$url="../temp/".$time0.$m.$endnums.".".$basename;
if(!is_dir("../temp/")){
mkdir("../temp/",0777,true);
}
if($type=="image/gif"||$type=="image/pjpeg"||$type=="image/jpeg"||$type=="image/jpg"){
list($RealWidth,$RealHeight)=getimagesize($tmp_name);//getimagesize取得图像大小
if($type=="image/pjpeg"||$type=="image/jpeg"||$type=="image/jpg"){
$img=imagecreatefromjpeg($tmp_name); //imagecreatefromjpeg从JPEG文件或URL新建一图像
}else if($type=="image/gif") {
$img=imagecreatefromgif($tmp_name);
}
$newwidth=12;
$newheight=10;
$new_img='';
$new_img = imagecreatetruecolor($newwidth, $newheight);//imagecreatetruecolor新建一个真彩色图像
imagecopyresized($new_img,$img,0,0,0,0,$newwidth,$newheight,$RealWidth,$RealHeight);
if ($type=="image/pjpeg"||$type=="image/jpeg"||$type=="image/jpg") {
imagejpeg($new_img,$url,100);
}else if($type=="image/gif"){
imagegif($new_img,$url,100);
}
$id_img=addslashes(file_get_contents($url));
}
echo $sql3="upadte person_img set img".($m+1)."='$id_img' where password='$password' limit 1";
mysql_query($sql3);
}
}数据库字段类型是mediumblob,数据库是GBK的,
echo sql语句可以看到二进制结果,
echo file_get_contents($url)也可以输出图片。
就是sql语句无法执行。
因为图片非常非常小,所以应该不存在数据包大小问题。就是数据库里头完全接收不到值。
for($m=0;$m<4;$m++){
if($_FILES['img'.($m+1)]['name']!=''){
$name=$_FILES['img'.($m+1)]['name'];
$type=$_FILES['img'.($m+1)]['type'];
$size=$_FILES['img'.($m+1)]['size'];
$tmp_name=$_FILES['img'.($m+1)]['tmp_name'];
$month=date('Ym');
$time0=substr(time(),-7);
$endnums=rand(1000,9999);
$thisname=explode(".",$name);
$basename=end($thisname);
$url="../temp/".$time0.$m.$endnums.".".$basename;
if(!is_dir("../temp/")){
mkdir("../temp/",0777,true);
}
if($type=="image/gif"||$type=="image/pjpeg"||$type=="image/jpeg"||$type=="image/jpg"){
list($RealWidth,$RealHeight)=getimagesize($tmp_name);//getimagesize取得图像大小
if($type=="image/pjpeg"||$type=="image/jpeg"||$type=="image/jpg"){
$img=imagecreatefromjpeg($tmp_name); //imagecreatefromjpeg从JPEG文件或URL新建一图像
}else if($type=="image/gif") {
$img=imagecreatefromgif($tmp_name);
}
$newwidth=12;
$newheight=10;
$new_img='';
$new_img = imagecreatetruecolor($newwidth, $newheight);//imagecreatetruecolor新建一个真彩色图像
imagecopyresized($new_img,$img,0,0,0,0,$newwidth,$newheight,$RealWidth,$RealHeight);
if ($type=="image/pjpeg"||$type=="image/jpeg"||$type=="image/jpg") {
imagejpeg($new_img,$url,100);
}else if($type=="image/gif"){
imagegif($new_img,$url,100);
}
$id_img=addslashes(file_get_contents($url));
}
echo $sql3="upadte person_img set img".($m+1)."='$id_img' where password='$password' limit 1";
mysql_query($sql3);
}
}数据库字段类型是mediumblob,数据库是GBK的,
echo sql语句可以看到二进制结果,
echo file_get_contents($url)也可以输出图片。
就是sql语句无法执行。
因为图片非常非常小,所以应该不存在数据包大小问题。就是数据库里头完全接收不到值。
你测试过可以输出图片? file_get_contents($url) 的返回值应该是一长串乱码吧?如果是返回值真是乱码的话,你这种数据库插入语句是写不进去的,因为里面有很多乱七八糟的字符你真的要存入数据库 你可以先base64_encode() 数据库字段换成字符串类型 下次读出来的时候base64_decode()就是你file_get_contents的返回值了只是你要这东西干什么 你要存图片的话 还是存在服务器指定的文件夹内吧。尽管图片很小 读出来的也是乱码 而且还不短 这样设计数据库负担会很大的
应该是 blob 系列的,如果是 text 系列的那出错时必然的
看看都有什么
不过还真看不出来数据有什么问题
你 echo $sql3; 对比一下
echo base64_encode(file_get_contents($url));
如用 addcslashes 转义,却又取不回来
还是用 base64 转义不会有问题入库前 $id_img = base64_encode(file_get_contents($url));
出库后 $im1 = base64_decode($row['im1'];
映像中,以前的版本中都没有这种问题
数据库类型还是用mediumblob么??、
代码如上,还是提示如下错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'upadte person_img set img1='/9j/4AAQSkZJRgABAQAAAQABAAD//gA8Q1JFQVRPUjogZ2QtanBl' at line 1
找到了!!!!
sql语句中错了两个字母!!!好几天啊啊啊 啊啊