php上传字段保存到mysql
php code if($dsql->executenonequery($sql)) { //文件存储路径 $file_path=../upload/; //664权限为文件属主和属组用户可读和写,其他用户只读 if(is_dir($file_path)!=true) mkdir($file_path,0664); //定义允许上传的文件扩展 $ext_arr = array(gif, jpg, jpeg, png, bmp, txt, zip, rar); //获得文件扩展名 $temp_arr = explode(., $_files[photo][name]); $file_ext = array_pop($temp_arr); $file_ext = trim($file_ext); $file_ext = strtolower($file_ext); //获取上传文件的信息赋给变量 $upfile = $_files['photo']; $photo = $upfile; //以时间戳重命名文件 $new_name = time()...$file_ext; //将文件移动到存储目录下 move_uploaded_file($_files[photo][tmp_name],$file_path . $new_name); //向数据表写入文件存储信息以便管理 foreach($items as $key=>$val) { $val['price'] = str_replace(,,,$val['price']); $dsql->executenonequery(insert into `#@__shops_products` (`aid`,`oid`,`userid`,`title`,`price`,`buynum`) values ('$val[id]','$ordersid','$userid','$val[title]','$val[price]','$val[buynum]');); } $sql = insert into `#@__shops_userinfo` (`userid`,`oid`,`consignee`,`address`,`zip`,`tel`,`email`,`qq`,`cphm`,`t1`,`t2`,`period`,`des`,`dabh`,`photo`,`scanning`) values ('$userid','$ordersid','$postname','$address','$zip','$tel','$email','$qq','$cphm','$t1','$t2','$period','$des','$dabh','$photo','$scanning'); ; $dsql->executenonequery($sql); } else { showmsg(更新订单时出现错误!.$dsql->geterror(),-1); exit(); } } else { $sql = update `#@__shops_orders` set `cartcount`='$cartcount',`price`='$pricecount',`ip`='$ip',`stime`='$stime',pid='$pid',paytype='$paytype',dprice='$dprice',pricecount='$lastpricecount' where oid='$ordersid' and userid='$userid' ;; if($dsql->executenonequery($sql)) { $sql = update `#@__shops_userinfo` set `consignee`='$postname',`address`='$address',`zip`='$zip',`tel`='$tel',`email`='$email',`qq`='$qq',`cphm`='$cphm',`t1`='$t1',`t2`='$t2',`period`='$period',`des`='$des',`dabh`='$dabh',`photo`='$photo',`scanning`='$scanning' where oid='$ordersid';; $dsql->executenonequery($sql); } else { echo $dsql->geterror(); exit; } unset($sql); }
为什么表单提交后photo字段显示成array而不是图片上传后的路径?文件是能上传提交上去的,那个地方出了问题还请高手赐教!!!!
------解决方案--------------------
与字段 photo 对应的是变量 $photo
而
$photo = $upfile;
且
$upfile = $_files['photo'];
是一个数组
你应该将 $file_path . $new_name 存入 photo 字段
但 $file_path 中的 ../ 可能会给后期使用带来麻烦