无法重命名 $_POST 中的文件夹

Can not rename a folder inside $_POST

我浏览了该站点中的许多参考资料,发现它可以成功运行:

<?php 
//tes to rename a sub folder
$oldDir="test";
$newDir = "testing";

if (!is_dir(dirname($newDir))) {
    mkdir(dirname($newDir), 0777, true);
}

rename($oldDir,$newDir);
echo 'successfully renamed into';
?>

现在,我需要重命名一个类别标签(目录)。但是,它给了我错误: "warning"."No such file or directory in ...." 当我在 $_POST 中有一个类别名称时,如下图所示:

第一,submit.php

<?php
$displCat = $mydb->prepare("SELECT * FROM labelz ORDER BY label_name");
$displCat->execute();
$dataCat = $displCat->fetchAll();
    foreach ($dataCat as $tampil_cat) {
    $idcat=$tampil_cat['id'];
    $cat=$tampil_cat['label_name'];
    ?>

<form action="u.php?id=<?php echo $idcat; ?>" method="post" name="frmupdatekat">
<div class="modal-body" style="overflow:auto;">
<h4>Edit Kategori: <?php echo $idcat.". ".$cat; ?></h4>
<input type="text" class="form-control" id="txtOldKat" name="txtOldKat" value="<?php echo $cat; ?>" style="border:0px;"/>
<input type="text" class="form-control" id="txtUpdateKategori" name="txtUpdateKategori"/>
<br />
<input type="submit" name="cmdUpdateKategori" id="cmdUpdateKategori" class="btn btn-success" style="vertical-align:middle; height:27px; padding:4px; font:12px Arial;" value="Update Kategori"/>
<br />
<br />
</div>
</form>
//.......
?>

第二,u.php

<?php
session_start();
include('conn.php');

if (isset($_GET['id'])){
    $id=isset($_GET['id']) ? $_GET['id'] : '';
    $txtOldKat=trim($_POST['txtOldKat']);
    $txtUpdateKategori=trim($_POST['txtUpdateKategori']);

rename($txtOldKat,$txtUpdateKategori);
echo "<script>alert('Haadeeeehhh, ini koq error muluuuuuuuuuuuu!');</script>";
exit(); // stop to see if errors here.

if (isset($_POST['cmdUpdateKategori'])){
    if (empty($_POST['txtUpdateKategori'])){
        echo "<script>alert('Admin, Anda belum mengganti nama Kategori!');</script>";
        echo "<meta http-equiv='refresh' content='0; url=adminz/kategori.php?target=kategori'>";
        exit();
        }
    else{
        $sql="SELECT * FROM labelz WHERE id=:id";
        $sth = $mydb->prepare($sql);
        $sth->execute(array(':id' => $id ));

//....... others code
?>

然后我使用了以前的脚本,但甚至无法使用:

__DIR__
__dirname(__FILE__)
realpath()

等等

我还检查 $old_cat 是否存在并且它确实存在。 这是 filezilla 的屏幕截图(也可以在 cpanel 中查看)。

然后尝试在 post 值中使用 trim()。 我还在这里阅读:http://php.net/manual/en/function.rename.php 看看我是否错了。

里面好像不行 $_POST.
那么,既然我需要它在 $_POST 里面做什么,我该怎么办呢? 否则,您可能有其他解决方案。

如果您发现这是重复的问题,请告诉我 link。
非常感谢您的 advice/suggestion/solution.

在你的代码中做一些错误检查,确保 $old_cat 在重命名之前存在,确保 $new_cat 实际上是一个有效的 file/folder 名称并且不存在,确保 $old_cat$new_cat 已实际设置。