2011-04-25 29 views
-1

我需要移动文件(而不是删除文件)。如何使用此代码移动文件

我该如何使用此代码做到这一点?

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([email protected]($f)){ 
    $ret['status']=3; 
    echo $_GET['cb']."(".json_encode($ret).");"; 
    die(); 
} 
echo $_GET['cb']."(".json_encode($ret).");"; 
die(); 
} 
+1

正如已经在你的[上一个问题,](http://stackoverflow.com/questions/5777238/how-to-move-a-file-using-this-code)的评论中说这不是如何堆栈溢出应该工作。请提出具体的技术问题,而不是“修复我的代码”请求。 – 2011-04-25 10:09:13

回答

0

要移动文件,请使用rename()。我想现在你知道如何移动一个文件,实际上它会很容易实现。

+0

如何应用“rename(”/ $ file_name“,”/ _temp/$ file_name“);”以上例子 – Tharindu 2011-04-25 10:08:04