php如何向MYSQL里插入图片或者图片路径?
<?phpsession_start();include("conn.php");$mingcheng=$_POST[mingcheng];$nian=$_POST[ni...
<?php
session_start();
include("conn.php");
$mingcheng=$_POST[mingcheng];
$nian=$_POST[nian];
$yue=$_POST[yue];
$ri=$_POST[ri];
$price=$_POST[price];
$meas=$_POST[meas];
$upfile=$_POST[upfile];
$packing=$_POST[packing];
function getname($exname){
$dir = "upimages/";//列出产品图片的上传目录
$i=1;
if(!is_dir($dir)){
mkdir($dir,0777);
}
while(true){
if(! is_file($dir.$i.".".$exname)){
$name=$i.".".$exname;
break;
}
$i++;
}
return $dir.$name;
}
$exname=strtolower(substr($_FILES['upfile']['name'],(strrpos($_FILES['upfile']['name'],'.')+1)));
$uploadfile = getname($exname);
move_uploaded_file($_FILES['upfile']['tmp_name'],$uploadfile);
if(trim($_FILES['upfile']['name']!="")){
$uploadfile="admin/".$uploadfile;
}
else{
$uploadfile="";
}
$addtime=$nian."-".$yue."-".$ri;
mysql_query("insert into tb_shangpin(mingcheng,meas,addtime,tupian,packing,price)values
('$mingcheng','$meas','$addtime','$tupian','$packing','$price')",$conn);
echo "<script> alert('product ".$mingcheng." uploaded successfully!');windows.location.href='addgoods.php';</script>";
?> //上传成功转向addgoods.php页面
按照这个代码 上传图片 数据表里图片那个栏显示空白 展开
session_start();
include("conn.php");
$mingcheng=$_POST[mingcheng];
$nian=$_POST[nian];
$yue=$_POST[yue];
$ri=$_POST[ri];
$price=$_POST[price];
$meas=$_POST[meas];
$upfile=$_POST[upfile];
$packing=$_POST[packing];
function getname($exname){
$dir = "upimages/";//列出产品图片的上传目录
$i=1;
if(!is_dir($dir)){
mkdir($dir,0777);
}
while(true){
if(! is_file($dir.$i.".".$exname)){
$name=$i.".".$exname;
break;
}
$i++;
}
return $dir.$name;
}
$exname=strtolower(substr($_FILES['upfile']['name'],(strrpos($_FILES['upfile']['name'],'.')+1)));
$uploadfile = getname($exname);
move_uploaded_file($_FILES['upfile']['tmp_name'],$uploadfile);
if(trim($_FILES['upfile']['name']!="")){
$uploadfile="admin/".$uploadfile;
}
else{
$uploadfile="";
}
$addtime=$nian."-".$yue."-".$ri;
mysql_query("insert into tb_shangpin(mingcheng,meas,addtime,tupian,packing,price)values
('$mingcheng','$meas','$addtime','$tupian','$packing','$price')",$conn);
echo "<script> alert('product ".$mingcheng." uploaded successfully!');windows.location.href='addgoods.php';</script>";
?> //上传成功转向addgoods.php页面
按照这个代码 上传图片 数据表里图片那个栏显示空白 展开
2个回答
展开全部
下面是我建立数据库及存图片的写法:
<?php
$a=mysql_connect("localhost", "root", "1234");
if(!$a)
{
die("数据库登录不成功:" . mysql_error());
}
if(mysql_query("CREATE DATABASE tp_db", $a))
{
echo "创建数据库成功";
}
else
{
echo ("创建数据库不成功:" . mysql_error());
}
mysql_select_db("tp_db" , $a);
$sql="CREATE TABLE image_sql(ID int Not Null AUTO_INCREMENT, primary key(ID), ImageName varchar(30), Image blob)";
mysql_query($sql, $a);
mysql_query("insert into image_sql(ID, ImageName, Image)
values(1, 'IPHONE车展名模', 'images/share_1.jpg')");
mysql_query("insert into image_sql(ID, ImageName, Image)
values(2, 'IPAD案例演示', 'images/share_2.jpg')");
mysql_query("insert into image_sql(ID, ImageName, Image)
values(3, 'IPAD日历演示', 'images/share_3.jpg')");
mysql_query("insert into image_sql(ID, ImageName, Image)
values(4, 'IPAD杂志演示', 'images/share_4.jpg')");
mysql_query("insert into image_sql(ID, ImageName, Image)
values(5, 'IPAD游戏演示', 'images/share_5.jpg')");
mysql_query("insert into image_sql(ID, ImageName, Image)
values(6, '疯狂农场', 'images/share_6.jpg')");
mysql_query("insert into image_sql(ID, ImageName, Image)
values(7, '虚拟社区商场', 'images/share_7.jpg')");
mysql_query("insert into image_sql(ID, ImageName, Image)
values(8, '脸谱拼图', 'images/share_8.jpg')");
mysql_close($a);
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询