求教,如何使文件上传后文件名字更改为想要的文件名?

求教,如何使文件上传后文件名字更改为想要的文件名?



[复制到剪切板]
CODE:
<?php

//文件保存目录路径
$save_path '../../upfile/';
//文件保存目录URL
$save_url 'http://www.cdtce.cn/dwpx/pxw/upfile/';
//定义允许上传的文件扩展名
$ext_arr = array('gif''jpg''jpeg''png''bmp');
//最大文件大小
$max_size 1000000;
//更改目录权限
@mkdir($save_path0777);

//有上传文件时
if (empty($_FILES) === false) {
    
//原文件名
    
$file_name $_FILES['imgFile']['name'];
    
//服务器上临时文件名
    
$tmp_name $_FILES['imgFile']['tmp_name'];
    
//文件大小
    
$file_size $_FILES['imgFile']['size'];
    
//检查文件名
    
if (!$file_name) {
        
alert("请选择文件。");
    }
    
//检查目录
    
if (@is_dir($save_path) === false) {
        
alert("上传目录不存在。");
    }
    
//检查目录写权限
    
if (@is_writable($save_path) === false) {
        
alert("上传目录没有写权限。");
    }
    
//检查是否已上传
    
if (@is_uploaded_file($tmp_name) === false) {
        
alert("临时文件可能不是上传文件。");
    }
    
//检查文件大小
    
if ($file_size $max_size) {
        
alert("上传文件大小超过限制。");
    }
    
//获得文件扩展名
    
$temp_arr explode("."$file_name);
    
$file_ext array_pop($temp_arr);
    
$file_ext trim($file_ext);
    
$file_ext strtolower($file_ext);
    
//检查扩展名
    
if (in_array($file_ext$ext_arr) === false) {
        
alert("上传文件扩展名是不允许的扩展名。");
    }
    
//移动文件
    
$file_path $_SESSION['upfilesuse'].$_SESSION['upfilestime'].$save_path $file_name;
    if (
move_uploaded_file($tmp_name$file_path) === false) {
        
alert("上传文件失败。");
    }
    
$file_url $save_url $file_name;
    
//插入图片,关闭层
    
echo '<html>';
    echo 
'<head>';
    echo 
'<title>Insert Image</title>';
    echo 
'<meta http-equiv="content-type" content="text/html; charset=utf-8">';
    echo 
'</head>';
    echo 
'<body>';
    echo 
'<script type="text/javascript">parent.KE.plugin["image"].insert("' $_POST['id'] . '", "' $file_url '","' $_POST['imgTitle'] . '","' $_POST['imgWidth'] . '","' $_POST['imgHeight'] . '","' $_POST['imgBorder'] . '");<\/script>';
    echo 
'</body>';
    echo 
'</html>';
}

//提示,关闭层
function alert($msg)
{
    echo 
'<html>';
    echo 
'<head>';
    echo 
'<title>error</title>';
    echo 
'<meta http-equiv="content-type" content="text/html; charset=utf-8">';
    echo 
'</head>';
    echo 
'<body>';
    echo 
'<script type="text/javascript">alert("'.$msg.'");history.back();<\/script>';
    echo 
'</body>';
    echo 
'</html>';
    exit;
}
?> ;


以上是一段在线编辑器的文件上传代码,我想改变几点效果,但不知道怎么改,请指教:

我要的是当文件上传后,文件名会更改为:$_SESSION['upfile'].$_SESSION['time'].$file_name
谢谢、

[ 本帖最后由 蝶舞飘香 于 2009-4-12 03:50 编辑 ]

就改变保存的路径,改
$file_path = $_SESSION['upfilesuse'].$_SESSION['upfilestime'].$save_path . $file_name;

$file_path = $_SESSION['upfilesuse'].$_SESSION['upfilestime'].$save_path . $_SESSION['upfile'].$_SESSION['time'].$file_name;
如履薄冰

没错,版主说的很对