-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
169 lines (141 loc) · 4.95 KB
/
index.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/*****this is to tweak*****/
$pass_check="12345";
$upload_local_dir="Z:/xampp/htdocs/upload/uploads";
$upload_url="/upload/uploads";
/*************************/
/***Actual code starts here...***/
$result ="";
if($_POST){
$uploadtype = $_POST['uploadtype'];
//get the url
$password = $_POST['password'];
$url = $_POST['url'];
if ($password == $pass_check)
{
if (($uploadtype == "url") && (filter_var($url, FILTER_VALIDATE_URL)))
{
//add time to the current filename
$result = "Error: invalid url";
$path = parse_url($url, PHP_URL_PATH);
if(!empty($path))
{
$file_ext = pathinfo($path, PATHINFO_EXTENSION);
$txt = basename(pathinfo($path,PATHINFO_BASENAME),".".$file_ext);
$name = $txt.time();
if (!empty($file_ext))
$name = $name.".".$file_ext;
$contents = file_get_contents($url);
if ($contents != FALSE)
{
$dir = $upload_local_dir."/".$name;
$upload = file_put_contents($dir,$contents);
//check success
if($upload) {
$result= "Success: <a href='".$upload_url."/".$name."' target='_blank'>File uploaded</a>";
}
else
{
$result= "Error: Please check free space and directory permissions...";
}
}
else
{
$result = "Error: Download failed...";
}
}
}
elseif (($uploadtype == "file") && ( $_FILES['filebutton']['error'] !== UPLOAD_ERR_NO_FILE))
{
if(isset($_FILES['filebutton'])){
$file_name = $_FILES['filebutton']['name'];
$file_size =$_FILES['filebutton']['size'];
$file_tmp =$_FILES['filebutton']['tmp_name'];
$file_type=$_FILES['filebutton']['type'];
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
$txt = basename(pathinfo($file_name,PATHINFO_BASENAME),".".$file_ext);
$new_name = $txt.time();
if (!empty($file_ext))
$new_name = $new_name.".".$file_ext;
if (move_uploaded_file($file_tmp,$upload_local_dir."/".$new_name))
{
$result= "Success: <a href='".$upload_url."/".$new_name."' target='_blank'>File uploaded</a>";
}
else
{
$result= "Error: Cannot upload file!";
}
}
}
else
{
$result = "Probably you missed something...";
}
}
else
{
$result = "Error: Password does not match...";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<script type="text/javascript" src="http://code.jquery.com/jquery-3.1.0.slim.min.js"></script>
<script type="text/javascript" src="js/code.js"></script>
<link rel="stylesheet" href="css/style.css" />
<title>Image Uploader Script</title>
</head>
<body>
<form class="form-horizontal" id="upload-form" method="post" enctype="multipart/form-data">
<fieldset>
<!-- Form Name -->
<legend>Uploader</legend>
<!-- Multiple Radios -->
<div class="form-group"> <label class="col-md-4 control-label" for="uploadtype">Upload type</label>
<div class="col-md-4">
<div class="radio"> <label for="uploadtype-file"> <input name="uploadtype"
id="uploadtype-file" value="file" checked="checked" type="radio">
Upload file </label> </div>
<div class="radio"> <label for="uploadtype-url"> <input name="uploadtype"
id="uploadtype-url" value="url" type="radio"> Set URL </label>
</div>
</div>
<hr>
</div>
<!-- Text input-->
<div class="form-group" id="id_url"> <label class="col-md-4 control-label" for="url">Enter
URL</label>
<div class="col-md-4"> <input id="url_data" name="url" placeholder="http://funny.com/cat.jpg"
class="form-control input-md" type="text"> <span class="help-block">Enter
URL of image</span> </div>
<hr>
</div>
<!-- File Button -->
<div class="form-group" id="id_file"> <label class="col-md-4 control-label" for="filebutton">Select
file to upload</label>
<div class="col-md-4"> <input id="file_data" name="filebutton" class="input-file"
type="file"> </div>
<hr>
</div>
<!-- Password input-->
<div class="form-group"> <label class="col-md-4 control-label" for="password">Password</label>
<div class="col-md-4"> <input id="password" name="password" placeholder="password"
class="form-control input-md" required="" type="password"> <span
class="help-block">Enter your password</span> </div>
<hr>
</div>
<!-- Button -->
<div class="form-group"> <label class="col-md-4 control-label" for="submit_button">Press
to upload</label>
<div class="col-md-4"> <button id="submit_button" name="submit_button"
class="btn btn-primary">Process</button> </div>
</div>
</fieldset>
</form>
<div id="result">
<?php echo $result ?>
</div>
</body>
</html>