php怎么把图片路径存到mysql数据库,求这样的代码

2024-11-15 18:40:38
推荐回答(2个)
回答1:

存储部分

include("conn.php");
$number=$_POST['number'];
$itemname=$_POST['itemname'];
$price=$_POST['price'];
$meas=$_POST['meas'];
$picture=$_POST['picture'];
$packing=$_POST['packing'];
$material=$_POST['material'];
$addtime=$_POST['addtime'];
$name=$_FILES['picture']['name'];
$picture=$_FILES['picture']['tmp_name'];
$fp=fopen($picture,'r');
$data=addslashes(fread($fp,filesize($picture)));
$sql="insert into product(number,meas,itemname,addtime,picture,packing,price,material)values
('$number','meas','$itemname','$addtime','$picture','$packing','$price','$material')";
mysql_query($sql,$conn) or die("插入数据失败:".mysql_error());

mysql_close($conn);
if($_FILES['picture']['error']>0){
echo "上传出错"; }
else {
echo "上传成功";
}//From J.L
print_r($_POST);exit;
?>

显示部分
$sql=mysql_query("select * from product where price!=0 order by addtime desc limit 12,100");
//按price的值调用
$info=mysql_fetch_array($sql);
if(empty($info)){
echo "No product";
}
else{
?>


if( empty($info['picture'])){
echo"No Pictures";
}
else{
?>

。。。。。。
为什么显示不出图片?
数据表里图片存储路径 如 :D:xampp mpphpB931.tmp

回答2:

有什么疑问?当然可以保存路径.图片上传到服务器后,把存放图片的路径存到数据库里面.