forked from nil0x42/phpsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileAccess.php
More file actions
44 lines (39 loc) · 1.19 KB
/
Copy pathfileAccess.php
File metadata and controls
44 lines (39 loc) · 1.19 KB
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
<?
// fileAccess($abspath, $mode) (type => boolean):
// Check if $abspath has $mode permission.
//
// $abspath (string):
// This variable must link to a regular file.
// $mode (char):
// 'r': Check if readable
// 'w': Check if writable
// 'x': Check if executable
//
// EXAMPLE:
// >>> fileAccess("/etc/passwd", 'r')
// True
// >>> fileAccess("/etc/passwd", 'w')
// False
function fileAccess($abspath, $mode)
{
// Assuming cases where user wants to check write access, he
// will then pass 'w' as mode argument. Therefore, we just can't
// allow this mode internally, because doing a fopen() with 'w' mode
// will empty the file in case of success, which is clearly stupid.
if ($mode != 'r' && $mode != 'x')
$mode = 'a';
if ($mode == 'x')
return @is_executable($abspath);
// fopen() the given file path and return True in case of success
$old_mtime = @filemtime($abspath);
$old_atime = @fileatime($abspath);
if ($h = @fopen($abspath, $mode))
{
fclose($h);
@touch($abspath, $old_mtime, $old_atime);
return (True);
}
else
return (False);
}
?>