开发者

How to move a file using this code

I need to move a file (instead of deleting a file).

How can I do that using this code?

JavaScript code:

function deleteFile(path){
if(!loggedin){
    noPerms();
    return 0;
}
var name=basename(path);
$("#editfile_modal").append('Are you sure you want to delete <strong>'+name.escape()+'</strong>?');
$("#editfile_modal").dialog({
    title: 'File Deletion Confirmation - '+name.escape(),
    modal: true,
    width: 500,
    height: 215,
    buttons: {
        'Delete': function() {
            $(this).dialog('close');
            $.getJSON(t_dn+"_tastydir/do.php?delf="+urlencode(path)+"&cb=?", function(data){
                if(data.status>0){
                    $("#editfile_modal").dialog({
                        title: 'File Deletion Error - '+name.escape(),
                        modal: true,
                        width: 500,
                        height: 215,
                        buttons: {
                            'Close': f开发者_运维问答unction() {
                                $(this).dialog('close');
                            }
                        },
                        close: function(event,ui){
                            $(this).empty();
                        }
                    });
                    if(data.status==1){
                        $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to delete doesn\'t exist.');
                    }else if(data.status==2){
                        $("#editfile_modal").append('<h3 class="no">Error</h3> The file you\'re trying to delete isn\'t writable. Please set permissions of at least 755 in order to be able to modify files.');
                    }else if(data.status==3){
                        $("#editfile_modal").append('<h3 class="no">Error</h3> For some reason, the file couldn\'t be deleted. This is most likely a permission issue. Sorry!');
                    }else if(data.status==100){
                        $("#editfile_modal").append('<h3 class="no">Error</h3> Access denied.');
                    }else{
                        $("#editfile_modal").append('<h3 class="no">Error</h3> Error code '+data.status+'.');
                    }
                }else{
                    updateFiles(document.location.hash.substr(1));
                }
            });
        },
        'Cancel': function() {
            $(this).dialog('close');
        }
    },
    close: function(event,ui){
        $(this).empty();
    }
});
}

php code :

if(!empty($_GET['delf'])){
// status codes:
// 0    ok
// 1    file doesn't exist
// 2    file isn't writable
// 3    couldn't delete
$f=stripslashes(rawurldecode($_GET['delf']));
$ret=array('status'=>0);
if(!file_exists($f)){
    $ret['status']=1;
    echo $_GET['cb']."(".json_encode($ret).");";
    die();
}
if(!is_writable($f)){
    $ret['status']=2;
    echo $_GET['cb']."(".json_encode($ret).");";
    die();
}
if(!@unlink($f)){
    $ret['status']=3;
    echo $_GET['cb']."(".json_encode($ret).");";
    die();
}
echo $_GET['cb']."(".json_encode($ret).");";
die();
}


Use rename in PHP.


To move a file, use rename(). I guess it'll be easy for you to actually implement it now that you know how to move a file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜