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"];
if ($_FILES["tupian"]['error'] == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["tupian"]["tmp_name"];
$name = $_FILES["tupian"]["name"];
move_uploaded_file($tmp_name, "$name");//在这里进行文件改名
}
echo '<img src="' . $name . '" />';
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 "上传成功";
}
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="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"];
if ($_FILES["tupian"]['error'] == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["tupian"]["tmp_name"];
$name = $_FILES["tupian"]["name"];
move_uploaded_file($tmp_name, "$name");//在这里进行文件改名
}
echo '<img src="' . $name . '" />';
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 "上传成功";
}
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="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> 展开
2个回答
展开全部
<?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"];
if ($_FILES["tupian"]['error'] == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["tupian"]["tmp_name"];
$name = $_FILES["tupian"]["name"];
move_uploaded_file($tmp_name, "$name");//在这里进行文件改名
}
echo '<img src="' . $name . '" />';
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 "上传成功";
}
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="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"];
if ($_FILES["tupian"]['error'] == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["tupian"]["tmp_name"];
$name = $_FILES["tupian"]["name"];
move_uploaded_file($tmp_name, "$name");//在这里进行文件改名
}
echo '<img src="' . $name . '" />';
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 "上传成功";
}
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="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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询