代码如下
以下代码是我建立一个upload.php的文件。 Form表单是在另外一个页面中,然后提交到upload中的。 一下代码, 已经实现了把图片上传到 uploads文件中,也已经实现了,更换更换图片名字。 下面那个insert 语句,单独可以使用,但是当我把他们俩融合在一起是,却不能插入数据。我是想把 图片地址上传到数据库中。求解答。多谢。
<?php
function type() {
return substr(strrchr($_FILES['hotelimg']['name'],'.'),1);
}
$type=array("jpg","gif","bmp","jpeg","png");
$uploaddir="./uploads/";
if(!in_array(strtolower(type()),$type)){
$text=implode('.',$type);
echo "You are allowed upload the following type of file: ",$text,"<br>";
}else
{
$filename=explode(".",$_FILES['hotelimg']['name']);
$time=date("y.m.d");
$filename[0]=$time;
$name=implode(".",$filename);
$uploadfile=$uploaddir.$name;
echo $name."<br>".$uploadfile;
}
if(move_uploaded_file($_FILES['hotelimg']['tmp_name'],$uploadfile))
{
$hotelname=$_POST[hotelname];
$hoteladdress=$_POST[hoteladdress];
$hoteltel=$_POST[hoteltel];
$area=$_POST[area];
echo $hotelname."<br>".$hoteladdress."<br>".$hoteltel."<br>".$area;
$sql="insert into hotelinfo(hotelid,hotelimg,hotelname,hoteladdress,hoteltel,area) values('','$name','$hotelname','$hoteladdress','$hoteltel','$area')";
if(mysql_query($sql)){
echo "Add hotel sucessfully";
}else{
echo "Add hotel Failed";
}
}
else
{
echo"Upload img Failed!";
}
?>
以下代码是我建立一个upload.php的文件。 Form表单是在另外一个页面中,然后提交到upload中的。 一下代码, 已经实现了把图片上传到 uploads文件中,也已经实现了,更换更换图片名字。 下面那个insert 语句,单独可以使用,但是当我把他们俩融合在一起是,却不能插入数据。我是想把 图片地址上传到数据库中。求解答。多谢。
<?php
function type() {
return substr(strrchr($_FILES['hotelimg']['name'],'.'),1);
}
$type=array("jpg","gif","bmp","jpeg","png");
$uploaddir="./uploads/";
if(!in_array(strtolower(type()),$type)){
$text=implode('.',$type);
echo "You are allowed upload the following type of file: ",$text,"<br>";
}else
{
$filename=explode(".",$_FILES['hotelimg']['name']);
$time=date("y.m.d");
$filename[0]=$time;
$name=implode(".",$filename);
$uploadfile=$uploaddir.$name;
echo $name."<br>".$uploadfile;
}
if(move_uploaded_file($_FILES['hotelimg']['tmp_name'],$uploadfile))
{
$hotelname=$_POST[hotelname];
$hoteladdress=$_POST[hoteladdress];
$hoteltel=$_POST[hoteltel];
$area=$_POST[area];
echo $hotelname."<br>".$hoteladdress."<br>".$hoteltel."<br>".$area;
$sql="insert into hotelinfo(hotelid,hotelimg,hotelname,hoteladdress,hoteltel,area) values('','$name','$hotelname','$hoteladdress','$hoteltel','$area')";
if(mysql_query($sql)){
echo "Add hotel sucessfully";
}else{
echo "Add hotel Failed";
}
}
else
{
echo"Upload img Failed!";
}
?>