move_uploaded_file不工作?

时间:2014-11-04 07:27:19

标签: php yii

我想将临时文件夹中的上传文件移动到新文件夹... oldpathnewpath是正确的但文件没有移动...我试过var_dump { {1}}并获得结果 bool(false)

以下是我的代码:

move_uploaded_file

我想念一些事吗?或者对此有何建议?感谢

2 个答案:

答案 0 :(得分:0)

我尝试使用copy然后unlink它有效! =)

$theid = Yii::app()->user->getState('id');
$folder = 'developers_apk'.DIRECTORY_SEPARATOR .$theid;

    if(!is_dir($folder)){
        mkdir($folder, 0755);
    }

    if(file_exists($folder)){
        $today = date("Ymd"); 
        $apkoldpath = Yii::app()->params['tmp_folder'] .$today.DIRECTORY_SEPARATOR.$apkfilename;
        $apknewpath = 'developers_apk'.DIRECTORY_SEPARATOR .$theid.DIRECTORY_SEPARATOR.$apkfilename;
        copy($apkoldpath,$apknewpath);

        $pngoldpath = Yii::app()->params['tmp_folder'] .$today.DIRECTORY_SEPARATOR.$pngfilename;
        $pngnewpath = 'developers_apk'.DIRECTORY_SEPARATOR .$theid.DIRECTORY_SEPARATOR.$pngfilename;
        copy($pngoldpath,$pngnewpath);

        if(file_exists($apknewpath)){
            unlink($apkoldpath);
        }
        if(file_exists($pngnewpath)){
            unlink($pngoldpath);
        }
    }

答案 1 :(得分:0)

您多次拨打move_uploaded_file(),这是不正确的。

试试这个:

if(file_exists($folder)){
    $today = date("Ymd"); 
    $oldpath = Yii::app()->params['tmp_folder'] .$today.DIRECTORY_SEPARATOR.$apkfilename;
    $newpath = 'developers_apk'.DIRECTORY_SEPARATOR .$theid.DIRECTORY_SEPARATOR.$apkfilename;

    if(move_uploaded_file($oldpath,$newpath)){              
        print_r("ok");
    }else{
        print_r("NOT"); 
    }
}else{
    print_r("NOT"); 
}