我需要移动文件(而不是删除文件)。
如何使用此代码执行此操作?
JavaScript代码:
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': function() {
$(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代码:
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();
}