每当新客户创建公司名称时,我都会使用php创建一个文件夹
$sql = "INSERT INTO kd_aboutus (business, category, subcategory, content, uafk, datein) VALUES ('$bn','$cat','$scat','$descr','$userID',now())";
$run_sql = mysqli_query($conn, $sql);
if (!file_exists("user/$bn")) {
mkdir("user/$bn", 0755);
}
现在,我的问题是,当用户想要编辑他或她的公司名称时,我还需要重命名他们已经创建的文件夹。我应该怎么做。 这是我在编辑文件中的代码
$sql = "UPDATE kd_aboutus SET business='$bn', category='$cat', subcategory='$scat', content='$descr' WHERE aboutID='$targetID'";
$run_sql = mysqli_query($conn, $sql);
答案 0 :(得分:3)
您将需要rename函数。请注意,最小参数为string $oldname , string $newname
,因此在更改数据库中的记录之前,您需要加载当前名称。
<?php
$query = "SELECT business FROM kd_aboutus WHERE aboutID='$targetID'";
if ($result = $mysqli->query($query)) {
$row = $result->fetch_assoc();
if (!empty($row['business'])) {
$oldBn = $row['business'];
rename("user/$oldBn", "user/$bn");
$sql = "UPDATE kd_aboutus SET business='$bn', category='$cat', subcategory='$scat', content='$descr' WHERE aboutID='$targetID'";
$run_sql = mysqli_query($conn, $sql);
}
}
以上内容未经测试,但应说明您需要实现的目标。
答案 1 :(得分:2)
在重命名之前,您首先必须获取当前文件夹名称。
SELECT business FROM kd_aboutus WHERE aboutID='$targetID';
通过变量获取上述查询的结果。假设$oldbn
然后,rename的文件夹为:
rename("user/$oldbn", "user/$bn");
$sql = "UPDATE kd_aboutus SET business='$bn', category='$cat', subcategory='$scat', content='$descr' WHERE aboutID='$targetID'";
$run_sql = mysqli_query($conn, $sql);
答案 2 :(得分:0)
PHP具有重命名文件夹/文件的功能:http://php.net/manual/en/function.rename.php
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content" style="width:130%;" >
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">ID: {{trace.ID}}'s Details</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="overview">
<p><span style="text-decoration:bold;color:#212529;">Login Name:</span> {{trace.WEBLGNNAME}}</p>
<p><span style="text-decoration:bold;color:#212529;">Datum:</span> {{trace.DATUM}}</p>
<p><span style="text-decoration:bold;color:#212529;">Zeit:</span> {{trace.ZEIT}}</p>
</div>
<!-- Stacktrace Field -->
<div class="form-group">
<label for="comment"></label>
<h5>Meldung</h5>
<textarea class="form-control" rows="2" columns="10" style="font-size:12px;" readonly id="Meldung">{{trace.LOGTEXT}}</textarea>
<div class="tooltip" title="In die Zwischenablage kopieren"><i ng-click="copyToClipboard('Meldung')" class="far fa-copy copy1"></br></i></div>
</div>
<!-- Stacktrace Field -->
<div class="form-group">
<label for="comment"></label>
<h5>Stacktrace</h5>
<textarea class="form-control" rows="10" columns="10" style="font-size:12px;" readonly id="Stacktrace">{{stacktrace}}</textarea>
<div class="tooltip1" title="In die Zwischenablage kopieren"><i ng-click="copyToClipboard('Stacktrace')" class="far fa-copy copy2"></br></i></div>
</div>
<div class="logInfo">
<div class="col1">
<p><span style="text-decoration:bold;color:#212529;">Web Service:</span> {{trace.WEBLGNNAME}}</p>
<p><span style="text-decoration:bold;color:#212529;">Label:</span> {{trace.DATUM}}</p>
<p><span style="text-decoration:bold;color:#212529;">Fehler Code:</span> {{trace.ZEIT}}</p>
</div>
<div class="col2">
<p><span style="text-decoration:bold;color:#212529;">Programm:</span> {{trace.WEBLGNNAME}}</p>
<p><span style="text-decoration:bold;color:#212529;">SQL Code:</span> {{trace.DATUM}}</p>
<p><span style="text-decoration:bold;color:#212529;">Fehler Typ:</span> {{trace.ZEIT}}</p>
</div>
<div class="col1">
<p><span style="text-decoration:bold;color:#212529;">Prozedur:</span> {{trace.WEBLGNNAME}}</p>
<p><span style="text-decoration:bold;color:#212529;">SQL State:</span> {{trace.DATUM}}</p>
<p><span style="text-decoration:bold;color:#212529;">Status BS:</span> {{trace.ZEIT}}</p>
</div>
<div class="col2">
<p><span style="text-decoration:bold;color:#212529;">Job User:</span> {{trace.WEBLGNNAME}}</p>
<p><span style="text-decoration:bold;color:#212529;">Job Name:</span> {{trace.DATUM}}</p>
<p><span style="text-decoration:bold;color:#212529;">Job Nummer:</span> {{trace.ZEIT}}</p>
</div>
<div class="col1">
<p><span style="text-decoration:bold;color:#212529;">Remote Addresse:</span> {{trace.WEBLGNNAME}}</p>
</div>
</div>
答案 3 :(得分:-1)
您应该使用rename()
函数。
refer from here (official)