FTP工具軟件會提示Permission Denied(沒有權(quán)限),或者 550刪除目錄操作失敗。今天小殘?jiān)诓僮鱂TP的時(shí)候就出現(xiàn)了這種問題。
出現(xiàn)的原因一般都是這些目錄或文件是PHP程序以管理員用戶寫入的,而一般虛擬主機(jī)的用戶名下的用戶又沒有管理員用戶組的權(quán)限,因此無法刪除。
大家在使用Linux的虛擬主機(jī)時(shí)候有沒有出現(xiàn)過通過FTP無法刪除網(wǎng)站路徑中的一些文件夾和文件
我們可以把下面這個(gè)PHP代碼放到對應(yīng)的虛擬主機(jī)的空間上運(yùn)行,按提示輸入文件夾或文件名即可。(注意這里最好使用相對路徑。)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<?php /* ####警告#### 本軟件為空間維護(hù)工具,使用完畢之后請立即刪除本文件 www.exehack.net */ ?> <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>空間文件夾/文件刪除工具</title> <style> body {font-family: "宋體" ; font-size:12px;} imput { border:1px #ccc solid;} b { color:#FF0000;} </style> </head> <body> <form action= "?action=dirdel" method= "post" > 刪除文件夾,<b>請確定填寫無誤后再進(jìn)行刪除操作!</b><br> 請輸入文件夾路徑,多個(gè)文件夾請使用 ";" 隔開 <input type= "text" name= "all_folder" size= "50" > <input type= "submit" value= "刪除" > </form> <br> <form action= "?action=filedel" method= "post" > 刪除文件,<b>請確定填寫無誤后再進(jìn)行刪除操作!</b><br> 請輸入完整的文件路徑,多個(gè)文件請使用 ";" 隔開 <input type= "text" name= "all_files" size= "50" > <input type= "submit" value= "刪除" > </form> <br> <?php $action = $_GET [ 'action' ]; //刪除目錄操作 if ( $action == 'dirdel' ) { $all_folder = $_POST [ 'all_folder' ]; if (! empty ( $all_folder )) { //根據(jù)分號識別多個(gè)文件夾 $folders = explode ( ';' , $all_folder ); if ( is_array ( $folders )) { foreach ( $folders as $folder ) { deldir( $folder ); echo $folder . '刪除成功<Br>' ; } } } } if ( $action == 'filedel' ) { $all_files = $_POST [ 'all_files' ]; if (! empty ( $all_files )) { //根據(jù)分號識別多個(gè)文件 $files = explode ( ';' , $all_files ); if ( is_array ( $files )) { foreach ( $files as $file ) { if ( is_file ( $file )) { if (unlink( $file )) { echo $file . '刪除成功<Br>' ; } else { echo $file . '無法刪除,請檢查權(quán)限<Br>' ; } } else { echo $file . '不存在<br>' ; } } } } } //刪除目錄及所包含文件函數(shù) function deldir( $dir ) { //打開文件目錄 $dh = opendir( $dir ); //循環(huán)讀取文件 while ( $file = readdir( $dh )) { if ( $file != '.' && $file != '..' ) { $fullpath = $dir . '/' . $file ; //判斷是否為目錄 if (! is_dir ( $fullpath )) { //如果不是,刪除該文件 if (!unlink( $fullpath )) { echo $fullpath . '小殘?zhí)崾?無法刪除,可能是沒有權(quán)限!<br>' ; } } else { //如果是目錄,遞歸本身刪除下級目錄 deldir( $fullpath ); } } } //關(guān)閉目錄 closedir ( $dh ); //刪除目錄 if ( rmdir ( $dir )) { return true; } else { return false; } } ?> </body> </html> |
為了防止出錯(cuò)大家也可以直接下載文件然后上傳到虛擬主機(jī)上。
下載地址:本地下載
下載好以后然后將 exehack.php上傳到虛擬主機(jī)根目錄,然后訪問該文件。
然后將要刪除的文件或者文件夾的路徑填寫上去
比如刪除min文件夾那么如下設(shè)置:
然后刷新下虛擬主機(jī)即可發(fā)現(xiàn)文件已被刪除。