【发布时间】:2015-03-23 08:32:08
【问题描述】:
我浏览了该站点中的许多参考资料,发现这很成功:
<?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 中查看)。
然后尝试在帖子值中使用trim()。
我也在这里阅读:http://php.net/manual/en/function.rename.php 看看我是不是错了。
好像里面不行 $_POST.
所以,我应该怎么做,因为我需要它在 $_POST 里面做。
否则,你可能有其他解决方案。
如果您发现这是重复的问题,请告诉我链接。
非常感谢您的建议/建议/解决方案。
【问题讨论】:
-
在你的代码中做一些错误检查,确保
$old_cat在重命名之前存在,确保$new_cat实际上是一个有效的文件/文件夹名称并且不存在,确保@实际设置了 987654335@ 和$new_cat等。 -
感谢您的回复。 $old_cat 存在。让我编辑我的问题以上传它的屏幕截图
-
另外,不要只使用
$_POST['old_cat'],使用trim($_POST['old_cat'])确保周围没有空格。 -
我也用 trim() 做了,但是真的不行,伙计.. 我在我的问题中包含了关于 trim() 的声明
-
$old_cat在您的表单中称为“phythonz”,您的文件夹称为“pythonz”