php怎么把图片路径存到mysql数据库,求这样的代码
2016-06-13
展开全部
存储部分
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
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;
?>
显示部分
<?php
$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{
?>
<tr>
<td width="200" rowspan="6">
<?php
if( empty($info['picture'])){
echo"No Pictures";
}
else{
?>
<img src="<?php echo $info['picture'];?>" width="158" height="160" border="0">
<?php
。。。。。。
为什么显示不出图片?
数据表里图片存储路径 如 :D:xampp mpphpB931.tmp
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
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;
?>
显示部分
<?php
$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{
?>
<tr>
<td width="200" rowspan="6">
<?php
if( empty($info['picture'])){
echo"No Pictures";
}
else{
?>
<img src="<?php echo $info['picture'];?>" width="158" height="160" border="0">
<?php
。。。。。。
为什么显示不出图片?
数据表里图片存储路径 如 :D:xampp mpphpB931.tmp
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询