我可能只需要一双新鲜的眼睛,这很愚蠢,但我遇到了这个问题:
我已经实现了内联文件夹重命名,例如:
$(function () {
$(".name").dblclick(function (e) {
e.stopPropagation();
var currentEle = $(this).children("a");
var value = currentEle.html();
updateVal(currentEle, value);
});
});
function updateVal(currentEle, value) {
var is_file = 0;
if(currentEle.hasClass('file')){
is_file = 1;
}
var rnm_dir = currentEle.attr('href');
rnm_dir = rnm_dir.replace('?dir=','');
$(currentEle).html('<input class="thVal" type="text" value="' + value + '" />');
$(".thVal").focus();
$(".thVal").keyup(function (event) {
if (event.keyCode == 13) {
var n_name = $(".thVal").val();
$('.thVal').remove();
$(currentEle).html(n_name);
$.ajax({
cache: false,
type: 'GET',
url: 'addfunctions.php',
data: {'rnm_dir':rnm_dir, 'is_file':is_file, 'new_name':n_name, 'function':'rename'},
dataType: "json",
beforeSend: function(){
console.log('ok');
},
success: function(response){
alert(response.name);
},
error: function (request, status, error) {
alert(request.responseText);
}
});
}
});
$(document).click(function () {
$(currentEle).html($(".thVal").val());
});
}
在控制台中我看到:
?rnm_dir=%3Fdir%3Dpress/Blackfield/Blackfield%25202/joijuoi&is_file=0&new_name=dcxfgdfxg&function=rename
但我收到原始目录丢失的错误rename(,/dcxfgdfxg)
但是,如果我将控制台输出直接运行到文件:
addfunctions.php?rnm_dir=%3Fdir%3Dpress/Blackfield/Blackfield%25202/New%2520Folder&is_file=0&new_name=joijuoi&function=rename
它实际上重命名了它
我的PHP是:
$is_file = $_GET['is_file'];
$rnm_dir = urldecode($_GET['rnm_dir']);
$new_name = $_GET['new_name'];
$rnm_dir = str_replace('?dir=','',$rnm_dir);
if($is_file){
$inf = pathinfo($rnm_dir);
$ext = $inf['extension'];
$dir = $inf['dirname'];
$n_file = $dir.'/'.$new_name.'.'.$ext;
rename($rnm_dir, $n_file);
$out['name'] = $n_file;
echo json_encode($out);
} else {
$dir = dirname($rnm_dir);
$n_dir = $dir.'/'.$new_name;
rename($rnm_dir, $n_dir);
$out['name'] = $n_dir;
echo json_encode($out);
}
修改为工作代码