php中上传的文件如何重命名并把重命名的名字传入数据库?请高手们帮帮忙,很急,希望能再我的源代码修改!
<?phpinclude("head.php");include("conn.php");if(is_uploaded_file(@$_FILES['upfile']['...
<?php
include("head.php");
include ("conn.php");
if(is_uploaded_file(@$_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"];
}
$name=@$upfile["name"];
$type=@$upfile["type"];
$size=@$upfile["size"];
$tmp_name=@$upfile["tmp_name"];
$error=@$upfile["error"];
switch($type){
case'image/pjpeg':$ok=1;break;
case'image/jpeg':$ok=1;break;
case'image/gif':$ok=1;break;
case'image/png':$ok=1;break;
}
if(@$ok&&$error=='0'){
move_uploaded_file($tmp_name,'up/'.$name);
echo "$name";
echo "$tmp_name";
echo "上传成功";
}
if(@$_POST['submit']){
$sql="insert into message (id,username,title,content,latedate) values ('','$_POST[username]','$_POST[title]','$_POST[content]',now())";
if(mysql_query($sql)){
echo"添加成功";
}
}
?>
<form action="add.php" method="POST" enctype="multipart/form-data" name="upform">
<input type="hidden" name="max_file_size" value="100000">
用户: <input type="text" name="username"/><br>
标题:<input type="text" name="title"/><br>
内容:<textarea name="content" cols="40" rows="5"></textarea><br>
上传文件:<input name="upfile" type="file">
<input type="submit" value="上传"><br><br>
<input type="submit" name="submit" value="发布留言" />
<input type="reset" value="重置">
</form> 展开
include("head.php");
include ("conn.php");
if(is_uploaded_file(@$_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"];
}
$name=@$upfile["name"];
$type=@$upfile["type"];
$size=@$upfile["size"];
$tmp_name=@$upfile["tmp_name"];
$error=@$upfile["error"];
switch($type){
case'image/pjpeg':$ok=1;break;
case'image/jpeg':$ok=1;break;
case'image/gif':$ok=1;break;
case'image/png':$ok=1;break;
}
if(@$ok&&$error=='0'){
move_uploaded_file($tmp_name,'up/'.$name);
echo "$name";
echo "$tmp_name";
echo "上传成功";
}
if(@$_POST['submit']){
$sql="insert into message (id,username,title,content,latedate) values ('','$_POST[username]','$_POST[title]','$_POST[content]',now())";
if(mysql_query($sql)){
echo"添加成功";
}
}
?>
<form action="add.php" method="POST" enctype="multipart/form-data" name="upform">
<input type="hidden" name="max_file_size" value="100000">
用户: <input type="text" name="username"/><br>
标题:<input type="text" name="title"/><br>
内容:<textarea name="content" cols="40" rows="5"></textarea><br>
上传文件:<input name="upfile" type="file">
<input type="submit" value="上传"><br><br>
<input type="submit" name="submit" value="发布留言" />
<input type="reset" value="重置">
</form> 展开
展开全部
1.$filename=explode(".",$_FILES['userfile']['name']);//把上传的文件名以“.”好为准做一个数组。 2.$time=date("m-d-H-i-s");//去当前上传的时间
3.$filename[0]=$time;//取文件名替换
4.name=implode(".",$filename); //上传后的文件名
5.$uploadfile=$uploaddir.$name;//上传后的文件名地址
插入数据库的时候 让图片的字段等于 $uploadfile
3.$filename[0]=$time;//取文件名替换
4.name=implode(".",$filename); //上传后的文件名
5.$uploadfile=$uploaddir.$name;//上传后的文件名地址
插入数据库的时候 让图片的字段等于 $uploadfile
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询