Linux virtual host space file or folder can not be deleted solution

  
 

When I maintain the blog file today, I found that I can't delete some folders and files in the website path through FTP. FTP prompt Permission Denied (no permission) makes me puzzled. I started looking for my own research ideas. Solution, since the FTP prompt permissions are insufficient, then it should be the problem in the file permissions setting of the server. I go to the server management background to view the file manager. The file manager displays the following figure:

It can be seen that the file owner generated by the PHP
program is the Apache account instead of my ftp account, so the Apache account has all the permissions to control these files but the FTP users do not, so I use my own on FTP. The user will delete the file system and will prompt me to delete them.

In order to determine the problem, I went to consult the server provider again. The answer is completely proof of my inference: general domestic Linux virtual host Apache and ftp are usually not in a user group, so the directory or file ftp created by apache can not be deleted, you must use php program to delete through Apache except.

How to solve it? Very simple, write a PHP program to complete this work


?php/* Linux Space File Remover Version 1.0 Copyright: Free Software, Random Spread# ###报警#### This software is a space maintenance tool. Please delete this file immediately after use. */?!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http: //www.w3.org/TR/html4/loose.dtd"htmlheadmeta http-equiv="Content-Type" content="text/html; charset=utf-8"titlespace folder/file removal tool/Titlestylebody {font-family:"宋体"; font-size:12px;}imput { border:1px #ccc solid;}b { color:#FF0000;}/style/headbodyform action="?action=dirdel" Method="post"Delete folder, bPlease make sure to fill in the correct operation after deleting it! /bbr Please enter the folder path, please use ";" separate input type="text" name ="all_folder" size="50"input type="submit" value="delete"/formbrform action="?action=filedel " method="post"Delete files, bPlease make sure to fill in the correct operation! /bbr Please enter the full file path, please use ";" separate input type="text" Name="all_files" size="50"input type="submit" value="delete"/formbr?php$action = $_GET['action'];//delete directory operation if($action =='dirdel') { $all_folder = $_POST['all_folder']; if(!empty($all_folder)) { //Recognize multiple folders by semicolon $folders = explode(';',$all_folder) ; if(is_array($folders)) { foreach($folders as $folder) { deldir($folder); echo $folder . 'Delete successful Br'; } } }}}if($action=='filedel') { $all_files = $_POST['all_files']; if(!empty($all_files)) { //Identifies multiple files by semicolon $files = explode(';',$all_files); if(is_array($files) { foreach($files as $file) { if(is_file($file)) { if(unlink($file)) { echo $file . 'Delete successful Br'; } else { echo $file . 'Cannot delete, Please check the permissions Br'; } } Else { echo $file . 'Do not exist br'; } } } }}//Delete directory and include file functions function deldir($dir) { //Open file directory $dh = opendir($dir); //loop Read the file while ($file = readdir($dh)) { if($file != '.' $file != '..') { $fullpath = $dir . '/' . $file; //Judge Is it a directory if(!is_dir($fullpath)) { //If not, delete the file if(!unlink($fullpath)) { echo $fullpath . 'Cannot delete, there may be no permissions! br'; } } else { //If it is a directory, recursively delete the subdirectory deldir($fullpath); } } } //close the directory closedir($dh); //delete the directory if(rmdir($dir)) { return true; } else { Return false; }}?/body/html

Copyright © Windows knowledge All Rights Reserved