Home  >  Article  >  Backend Development  >  一个奇怪的问题,rename文件错误,请帮看下

一个奇怪的问题,rename文件错误,请帮看下

WBOY
WBOYOriginal
2016-06-23 14:39:221462browse

代码如下:
$uploadfile = $uploaddir . basename($_FILES['music']['name']);
$musicname = basename($_FILES['music']['name']);

if (move_uploaded_file($_FILES['music']['tmp_name'], $uploadfile)) {

    $md5string = md5_file($uploadfile);
    if(stripos($uploadfile, ".mp3") !== false)
    {
     $filename2 = "/data/www/html/song/upload/m/".$subdir."/".$userid."/".$userid."_".$md5string.".mp3";
if(file_exists($filename2))
{
        unlink($uploadfile);
}
else
{
if(rename($uploadfile, $filename2))
{
}
else
{
}
}
}
服务器上错误文件如下(多了个~):


有遇到过类似问题的吗?


回复讨论(解决方案)

为什么不在move_uploaded_file()时的第二个参数,直接命名好名称呢?反而要在上传成功后,再去重命名?

因为文件传到服务器上面后,要计算下md5,然后重命名

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn