我有以下php脚本。所有查询均可,但无法删除该文件夹。我要删除的文件夹位于名为uploads的文件夹内,并且使用保存在数据库中的唯一ID的名称创建。为什么我不断获得许可的任何想法都会拒绝此类错误
警告:scandir(uploads / c71a8c3efbe52bff06e9cbd94c95ae00):未能 打开目录:权限被拒绝 /var/www/html/braiden/braintree/deleteTemplate.php,第43行
警告:scandir():(errno 13):权限被拒绝 /var/www/html/braiden/braintree/deleteTemplate.php,第43行
警告:为中的foreach()提供了无效的参数 /var/www/html/braiden/braintree/deleteTemplate.php,第46行
警告:rmdir(uploads / c71a8c3efbe52bff06e9cbd94c95ae00):目录 在/var/www/html/braiden/braintree/deleteTemplate.php中不为空 第56行
这是代码。请记住,除删除目录部分外,其他所有东西都有效。我只想给您更多有关上下文的代码。
<?php session_start(); ob_start();
require_once('database.php');
if(isset($_SESSION['admin']) and $_SESSION['admin']==1){
if(isset($_GET['id'])){$templateId=$_GET['id'];}
else{
header('Location:logout.php');
}
$selectExistsQuery="SELECT COUNT(*) AS exist FROM dataclayTemplates WHERE id='$templateId'";
$selectExistsResult=mysqli_query($mysqli, $selectExistsQuery);
while($row=mysqli_fetch_assoc($selectExistsResult)){
$exists=$row['exist'];
}
if($exists==1){
$selectItemIdQuery="SELECT itemId FROM dataclayTemplates WHERE id='$templateId'";
$itemIdResult=mysqli_query($mysqli, $selectItemIdQuery);
while($row=mysqli_fetch_assoc($itemIdResult)){
$itemId=$row['itemId'];
}
$deleteDataclayCategoriesLinkQuery="DELETE FROM dataclayCategoryLink WHERE templateId='$templateId'";
$deleteDataclayCategoriesLinkResult=mysqli_query($mysqli, $deleteDataclayCategoriesLinkQuery);
$deleteDataclayKeywordsLinkQuery="DELETE FROM dataclayKeywordLink WHERE templateId='$templateId'";
$deleteDataclayKeywordsLinkResult=mysqli_query($mysqli, $deleteDataclayKeywordsLinkQuery);
$deleteTextInstructionsQuery="DELETE FROM textInstructions WHERE templateId='$templateId'";
$deleteTextInstructionsResult=mysqli_query($mysqli, $deleteTextInstructionsQuery);
$deleteLayerInstructionsQuery="DELETE FROM layerInstructions WHERE templateId='$templateId'";
$deleteLayerInstructionsResult=mysqli_query($mysqli, $deleteLayerInstructionsQuery);
$deleteUploadInstructionsQuery="DELETE FROM uploadInstructions WHERE templateId='$templateId'";
$deleteUploadInstructionsResult=mysqli_query($mysqli, $deleteUploadInstructionsQuery);
$deleteColorInstructionsQuery="DELETE FROM colorInstructionsAndPresets WHERE templateId='$templateId'";
$deleteColorInstructionsResult=mysqli_query($mysqli, $deleteColorInstructionsQuery);
$deleteDataclayTemplateQuery="DELETE FROM dataclayTemplates WHERE id='$templateId'";
$deleteDataclayTemplateResult=mysqli_query($mysqli, $deleteDataclayTemplateQuery);
$folder='uploads/'.$itemId;
function removeFolder($folder){
if(is_dir($folder) ===true){
$folderContents = scandir($folder);
unset($folderContents[0], $folderContents[1]);
foreach($folderContents as $content=>$contentName){
$currentPath=$folder.'/'.$contentName;
$fileType=filetype($currentPath);
if($fileType == 'dir'){
removeFolder($currentPath);
} else{
unlink($currentPath);
}
unset($folderContents[$content]);
}
rmdir($folder);
}
}
removeFolder($folder);
if($deleteDataclayCategoriesLinkResult and $deleteDataclayKeywordsLinkResult and $deleteTextInstructionsResult and $deleteLayerInstructionsResult and $deleteUploadInstructionsResult and $deleteColorInstructionsResult and $deleteDataclayTemplateResult){
$data['success']=true; $data['error']=false;
} else{$data['success']=false; $data['error']=true;}
} else {header('Location:logout.php');}
} else {
header('Location:logout.php');
}
echo json_encode($data);
?>