我有以下功能,我试图用它来删除一个完整的文件夹,但它似乎没有删除任何想法或建议?
public function submit()
{
$location = $_SERVER['DOCUMENT_ROOT'].'/_assets/quote/uploads/';
$folderName = $this->quote->getCompanyDetails()->companyName;
$data['companyContact'] = $this->quote->getCompanyDetails()->companyContact;
$this->load->view('submit',$data);
$this->quote->removeQuote();
if(is_dir($location.$folderName) === TRUE)
{
$files = array_diff(scandir($location.$folderName), array('.','..'));
foreach($files as $file)
{
Delete(realpath($location.$folderName).'/'. $file);
}
return rmdir($location.$folderName);
}
else if(is_file($location.$folderName) === TRUE)
{
return unlink($location.$folderName);
}
return FALSE;
}
更新:
public function submit()
{
$location = $_SERVER['DOCUMENT_ROOT'].'/_assets/quote/uploads/';
$folderName = $this->quote->getCompanyDetails()->companyName;
$data['companyContact'] = $this->quote->getCompanyDetails()->companyContact;
$this->load->view('submit',$data);
//$this->quote->removeQuote();
$this->removeFolder();
}
private function removeFolder(){
$location = $_SERVER['DOCUMENT_ROOT'].'/_assets/quote/uploads/';
$folderName = $this->quote->getCompanyDetails()->companyName;
foreach(glob($location.$folderName.'/*') as $file)
{
if(is_dir($location.$folderName))
{
rmdir($location.$folderName);
}else{
unlink($location.$folderName);
}
rmdir($location.$folderName);
}
}