-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_upload.php
54 lines (53 loc) · 2.42 KB
/
image_upload.php
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
<?php
$result = "";
if ($_FILES['image']['name']) {
if (!$_FILES['image']['error']) {
if($_POST['action'] == 'insert') {
$_SERVER['HTTP_REFERER'] = str_replace('/insert.php', '', $_SERVER['HTTP_REFERER']);
$fsRoot = __DIR__;
$webRoot = str_replace($_SERVER['PHP_SELF'], '', $_SERVER['SCRIPT_FILENAME']);
$urlRoot = str_replace($webRoot, '', $fsRoot);
$file_dir = $webRoot . $urlRoot . '/img/';
$name = md5(rand(100, 200));
$ext = explode('.', $_FILES['image']['name']);
$filename = $name . '.' . $ext[1];
$destination = $file_dir.$filename;
$location = $_FILES["image"]["tmp_name"];
$moved = move_uploaded_file($location, $destination);
if($moved) {
$cmd1 = "chmod 777 ".$destination;
shell_exec($cmd1);
$result = $_SERVER['HTTP_REFERER'].'/img/'.$filename;
echo $result;exit;
} else {
$result = "Not uploaded because of error #".$_FILES['image']['error'];
echo $result;exit;
}
} else {
$fsRoot = __DIR__;
$webRoot = str_replace($_SERVER['PHP_SELF'], '', $_SERVER['SCRIPT_FILENAME']);
$urlRoot = str_replace($webRoot, '', $fsRoot);
$file_dir = $webRoot . $urlRoot . '/img/';
$name = md5(rand(100, 200));
$ext = explode('.', $_FILES['image']['name']);
$filename = $name . '.' . $ext[1];
$destination = $file_dir.$filename;
$location = $_FILES["image"]["tmp_name"];
$moved = move_uploaded_file($location, $destination);
if($moved) {
$cmd1 = "chmod 777 ".$destination;
shell_exec($cmd1);
$result = $_SERVER['HTTP_REFERER'].'/img/'.$filename;
echo $result;exit;
} else {
$result = "Not uploaded because of error #".$_FILES['image']['error'];
echo $result;exit;
}
}
}else{
$result = 'Ooops! Your upload triggered the following error: '.$_FILES['image']['error'];
echo $result;exit;
}
}
$result;
?>