php rename() Access is denied. (code: 5)

前端 未结 2 2075
广开言路
广开言路 2021-01-04 11:51

So I am trying to use rename function in php.

On the first try, if the destination folder is empty or does not contain any directories with the same name as the sour

相关标签:
2条回答
  • 2021-01-04 12:31

    If it is on Windows, this can be read in contributions:

    rename() definitely does not follow the *nix rename convention on WinXP with PHP 5. If the $newname exists, it will return FALSE and $oldname and $newname will remain in their original state. You can do something like this instead:

    function rename_win($oldfile,$newfile) {
        if (!rename($oldfile,$newfile)) {
            if (copy ($oldfile,$newfile)) {
                unlink($oldfile);
                return TRUE;
            }
            return FALSE;
        }
        return TRUE;
    }
    

    Link.

    0 讨论(0)
  • 2021-01-04 12:50

    You are adding extra / in path make this like

    /**
            *   Move temp folders to their permanent places
            *
            *   $module_folder = example (violator, pnp, etc)       
            *   $folders = name of folders within module_folder
            **/
            public function move_temp_to_permanent($module_folder, $folders){
                $bool = false;
    
                $module_folder_path = realpath(APPPATH . '../public/resources/temps/' . $module_folder);
    
                $module_folder_destination_path = $_SERVER['DOCUMENT_ROOT'] . '/ssmis/public/resources/photos/' . $module_folder . '/';
    
                foreach($folders as $folder){
                    $bool = rename($module_folder_path . $folder, $module_folder_destination_path . $folder);
                }
    
                return $bool;
            }
    

    you can also echo the path you prepared so you can check its right or not

    0 讨论(0)
提交回复
热议问题