Skip to content

Commit e40c1cb

Browse files
committed
v13 self destruct added
1 parent 5c13de2 commit e40c1cb

File tree

3 files changed

+145
-125
lines changed

3 files changed

+145
-125
lines changed

README.md

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
Upload File from URL to WebServer v. 12.0
1+
Upload File from URL to WebServer v.13
22
========================================
33

44
#### One click ready solution to upload a file from URL to your hosting storage (e.g. CPanel).
55

6-
> ~~Latest Publish Date: 2021/11/06 1400/08/15~~<br>
7-
> Latest Publish Date: 2024/05/10 1403/02/21
6+
> Latest Publish Date: 2024/08/18 1403/05/28
87
98

109
[View Demo Video](https://iranwpacademy.com/htdocs/img/2021/06/upload-to-cpanel-by-amirhosseinhpv.ir_.mp4)
@@ -20,22 +19,17 @@ new tab, then paste the URL you want to download and upload to your server, give
2019
it a name and hit UPLOAD. Easy as pie!
2120

2221
Hope you enjoy it, and BTW this tool is for personal use, so don’t get too
23-
serious about security bugs and stuff ;)
24-
25-
#### Change-log:
26-
27-
- Ver. 2.0: Added Real-time progress while uploading
28-
29-
- Ver. 3.0: Added Some styling and visuals
30-
31-
- Ver. 4.0: Fixed get file size error
32-
33-
- Ver. 5.0: More stability on large files processing
34-
35-
- Ver. 6.0: Added Timer, showing elapsed and total time
36-
37-
- Ver. 7.0: Added Auto file-name filler and Back to Root button
38-
39-
- Ver. 8.0: Added Compatibility with NON-SSL and DirectAdmin hosting
40-
41-
- Ver. 12.0: Added New features and stability.
22+
serious about security bugs and stuff ;) PS> don't forget to remove after you're done.
23+
24+
#### Changelog:
25+
26+
- Version 13: Added Self Destruct feature
27+
- Version 12: Added New features and stability.
28+
- Version 08: Added Compatibility with NON-SSL and DirectAdmin hosting
29+
- Version 07: Added Auto file-name filler and Back to Root button
30+
- Version 06: Added Timer, showing elapsed and total time
31+
- Version 05: More stability on large files processing
32+
- Version 04: Fixed get file size error
33+
- Version 03: Added Some styling and visuals
34+
- Version 02: Added Real-time progress while uploading
35+
- Version 01: Initiate release, at 2020/11/15 - 1399/08/25

blackswan.png

11.8 KB
Loading

upload.php

Lines changed: 129 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
<?php
33
/*
44
* @Author: Amirhossein Hosseinpour <https://amirhp.com>
5-
* @Date Created: 2024/02/15 19:31:15
5+
* @Date Created: 2020/11/15 19:31:15
66
* @Last modified by: amirhp-com <its@amirhp.com>
7-
* @Last modified time: 2024/02/20 14:30:52
7+
* @Last modified time: 2024/08/18 22:40:58
88
*/
9+
910
@ini_set("display_errors", 1);
1011
error_reporting(E_ERROR);
1112
?>
1213
<html>
1314

1415
<head>
15-
<title>Upload File from URL to WebServer v11</title>
16+
<title>Upload File from URL to WebServer v13</title>
1617
<style>
1718
* {
1819
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
@@ -27,6 +28,21 @@
2728
font-weight: 800;
2829
}
2930

31+
form {
32+
margin-top: 1rem;
33+
display: flex;
34+
flex-direction: column;
35+
align-content: center;
36+
justify-content: center;
37+
width: 100%
38+
}
39+
40+
form>* {
41+
align-self: center;
42+
margin-bottom: 1rem;
43+
min-width: 250px
44+
}
45+
3046
form div>span {
3147
font-size: small;
3248
position: absolute;
@@ -41,74 +57,80 @@
4157
color: #0060dfbd;
4258
}
4359

44-
form {
45-
margin-top: 1rem;
46-
display: flex;
47-
flex-direction: column;
48-
align-content: center;
49-
justify-content: center;
50-
width: 100%
51-
}
52-
5360
input:invalid {
5461
background-image: linear-gradient(45deg, transparent, transparent 50%, #df0000 50%, #ff7a7a 100%) !important;
5562
border-color: #df0000 !important;
5663
}
5764

58-
form>* {
59-
max-width: ;
60-
align-self: center;
61-
margin-bottom: 1rem;
62-
min-width: 250px
63-
}
64-
6565
input[required] {
6666
outline: none !important;
6767
background-image: linear-gradient(45deg, transparent, transparent 50%, #0060df 50%, #61a5ff 100%);
6868
background-position: top right;
6969
background-size: 1rem 1rem;
7070
background-repeat: no-repeat
7171
}
72+
73+
h1.aw {
74+
font-weight: 900;
75+
font-size: 3rem;
76+
margin: 0;
77+
color: #000;
78+
}
79+
80+
span.dw {
81+
color: #222;
82+
font-size: 1.3rem;
83+
display: block;
84+
margin: 0 0 -4rem 0;
85+
font-weight: normal;
86+
}
87+
88+
body.uffutw {
89+
text-transform: lowercase;
90+
font-family: Calibri;
91+
color: #222;
92+
text-align: center;
93+
margin-top: 5rem;
94+
}
95+
96+
small.red-alert {
97+
display: block;
98+
width: 345px;
99+
margin: auto;
100+
}
101+
102+
.red-alert,
103+
.red-alert a {
104+
text-transform: uppercase;
105+
font-weight: 800;
106+
color: #e32121;
107+
}
72108
</style>
73-
<script>
74-
setTimeout(function () {
75-
document.querySelector("#url").select();
76-
}, 200);
77-
</script>
109+
<link rel="icon" href="blackswan.png" sizes="32x32" />
110+
<link rel="icon" href="blackswan.png" sizes="192x192" />
78111
</head>
79112

80-
<body id="upload-file-from-url-to-webserver v-12" style="text-transform: lowercase; font-family: Calibri;color: #222; text-align: center;margin-top: 5rem;">
81-
<h1 style="font-weight: 900;font-size: 3rem;margin: 0;color: #000;">
82-
<span class="dw" style="color: #222;font-size: 1.3rem;display: block;margin: 0 0 -4rem 0;font-weight: normal;">
83-
Upload File Script v.12</span><br>URL-Address to WebServer</h1>
84-
<small>
85-
Developed by <a href="https://amirhp.com/" target="_blank">amirhp-com</a> |
86-
Give star on <a href="https://github.com/amirhp-com/upload-file-from-url-to-webserver" target="_blank">Github</a><br>
87-
Version 12.0 / Your IP: <?= get_real_IP_address(); ?><br>
88-
[ <a href="./">root</a> / <a href="?r=<?= time(); ?>">new?</a> ]
89-
</small>
90-
<br>
91-
<br>
113+
<body class="uffutw upload-file-from-url-to-webserver v-12">
114+
<h1 class="aw">
115+
<span class="dw">
116+
Upload File Script v.13</span><br>URL-Address to WebServer
117+
</h1>
92118
<?php
93-
function get_real_IP_address() {
94-
if (!empty($_SERVER['GEOIP_ADDR'])) {
95-
$ip = $_SERVER['GEOIP_ADDR'];
96-
} elseif (!empty($_SERVER['HTTP_X_REAL_IP'])) {
97-
$ip = $_SERVER['HTTP_X_REAL_IP'];
98-
} elseif (!empty($_SERVER['HTTP_CLIENT_IP'])) {
99-
$ip = $_SERVER['HTTP_CLIENT_IP'];
100-
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
101-
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
102-
} else {
103-
$ip = $_SERVER['REMOTE_ADDR'];
104-
}
105-
return $ip;
119+
if (isset($_GET["delete"]) && "true" == $_GET["delete"]) {
120+
unlink(__FILE__);
121+
die('<h3 class="red-alert" style="font-size: 1.5rem;">SELF-DESTRUCTION WAS SUCCESSFUL, BYE &#x1F44B;!</h3>');
106122
}
107-
if (isset($_POST['url'])) {
123+
?>
124+
<small>Developed by <a href="https://amirhp.com/" target="_blank">amirhp-com</a> | Give star on <a href="https://github.com/amirhp-com/upload-file-from-url-to-webserver" target="_blank">Github</a><br>
125+
Version 12.0 / Your IP: <?= get_real_IP_address(); ?><br> [ <a href="./">root</a> / <a href="?r=<?= time(); ?>">new?</a> ]</small>
126+
<br><br>
127+
<?php
128+
if (isset($_POST['url'], $_POST["name"])) {
108129
set_time_limit(24 * 60 * 60);
109-
$url = $_POST['url'];
110-
$name = $_POST['name'];
111-
$folder = $_POST['folder'];
130+
$url = $_POST["url"];
131+
$name = $_POST["name"];
132+
$folder = $_POST["folder"] ?? "";
133+
$folder = !empty($folder) ? rtrim($folder, '/\\') . "/" : "";
112134
ob_implicit_flush(true);
113135
ob_start();
114136
$server = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]";
@@ -121,6 +143,8 @@ function get_real_IP_address() {
121143
<div id=\"progress\"></div>`;</script>";
122144
$time = microtime(true);
123145
$remote = fopen($url, 'r');
146+
if (!is_dir($dirname)) mkdir($folder, 0777, true);
147+
if (file_exists($folder . $name)) unlink($folder . $name);
124148
$local = fopen($folder . $name, 'w');
125149
stream_context_set_default(array('http' => array('method' => 'HEAD')));
126150
$headers = get_headers($url, true);
@@ -140,7 +164,7 @@ function get_real_IP_address() {
140164
curl_exec($ch);
141165
curl_close($ch);
142166
fclose($fp);
143-
echo "<pre style='text-align: left; direction: ltr; border:1px solid gray; padding: 1rem; overflow: auto;'>". print_r($fp,1) ."</pre>";
167+
echo "<pre style='text-align: left; direction: ltr; border:1px solid gray; padding: 1rem; overflow: auto;'>" . print_r($fp, 1) . "</pre>";
144168
die("<br>Upload complete!");
145169
}
146170

@@ -159,13 +183,11 @@ function get_real_IP_address() {
159183
$num = 0;
160184
$steps = floor($filesize / 2048) / 300 < 0 ? 3 : floor($filesize / 2048) / 300;
161185
$progress = 1;
162-
echo "
163-
<script>
164-
document.title = 'Uploading " . sprintf("%'05.2f%%", $progress) . "';
165-
document.querySelector('#progress').innerHTML = '( " . sprintf("%'05.2f%%", $progress) . "" . human_filesize($filesize) . " )<br><small style=\"text-transform: capitalize;\">Elapsed Time: " . human_timing($time) . "</small>';
166-
document.querySelector('body').style.backgroundImage = 'linear-gradient(to right, rgba(0, 223, 56, 0.18) $progress%, white $progress%)';
167-
</script>
168-
";
186+
echo "<script>
187+
document.title = 'Uploading " . sprintf("%'05.2f%%", $progress) . "';
188+
document.querySelector('#progress').innerHTML = '( " . sprintf("%'05.2f%%", $progress) . "" . human_filesize($filesize) . " )<br><small style=\"text-transform: capitalize;\">Elapsed Time: " . human_timing($time) . "</small>';
189+
document.querySelector('body').style.backgroundImage = 'linear-gradient(to right, rgba(0, 223, 56, 0.18) $progress%, white $progress%)';
190+
</script>";
169191
while (!feof($remote)) {
170192
$buffer = fread($remote, 2048);
171193
fwrite($local, $buffer);
@@ -174,13 +196,11 @@ function get_real_IP_address() {
174196
if ($num > 4 && $steps > 1) {
175197
if ($num % $steps == 0) {
176198
$progress = min(100, 100 * $read_bytes / $filesize);
177-
echo "
178-
<script>
179-
document.title = 'Uploading " . sprintf("%'05.2f%%", $progress) . "';
180-
document.querySelector('#progress').innerHTML = '( " . sprintf("%'05.2f%%", $progress) . "" . human_filesize($read_bytes) . " / " . human_filesize($filesize) . " )<br><small style=\"text-transform: capitalize;\">Elapsed Time: " . human_timing($time) . "</small>';
181-
document.querySelector('body').style.backgroundImage = 'linear-gradient(to right, rgba(0, 223, 56, 0.18) $progress%, white $progress%)';
182-
</script>
183-
";
199+
echo "<script>
200+
document.title = 'Uploading " . sprintf("%'05.2f%%", $progress) . "';
201+
document.querySelector('#progress').innerHTML = '( " . sprintf("%'05.2f%%", $progress) . "" . human_filesize($read_bytes) . " / " . human_filesize($filesize) . " )<br><small style=\"text-transform: capitalize;\">Elapsed Time: " . human_timing($time) . "</small>';
202+
document.querySelector('body').style.backgroundImage = 'linear-gradient(to right, rgba(0, 223, 56, 0.18) $progress%, white $progress%)';
203+
</script>";
184204
}
185205
}
186206
ob_end_flush();
@@ -190,34 +210,16 @@ function get_real_IP_address() {
190210
}
191211
fclose($remote);
192212
fclose($local);
193-
echo "
194-
<script>
195-
document.title = 'Transferring Done!';
196-
document.querySelector('#progress').innerHTML = '( 100.00% — " . human_filesize($filesize) . " / " . human_filesize($filesize) . " )<br><small style=\"text-transform: capitalize;\">Total Time: " . human_timing($time) . "</small>';
197-
document.querySelector('body').style.backgroundImage = 'linear-gradient(to right, rgba(0, 223, 56, 0.18) $progress%, white $progress%)';
198-
document.querySelector('h1').innerHTML += '<div style=\"font-size: 0;margin-bottom: 3rem;\"><small style=\"font-size: 1rem;\">✅ Transferring Done! 👍</small></div>';
199-
document.querySelector('h1').innerHTML += '<div style=\"font-size: 0;margin-bottom: 3rem;\"><small style=\"font-size: 1rem;\"><a href=\"?r=" . time() . "\" style=\"background: #0060df;color: white;text-decoration: none; padding: 0.5rem 2rem;border: none;border-radius: 3px;box-shadow: 0 0 8px -3px #00000069;margin: 0 1rem;cursor: pointer;\">Upload another file</a></small></div>';
200-
</script>
201-
";
213+
echo "<script>
214+
document.title = 'Transferring Done!';
215+
document.querySelector('#progress').innerHTML = '( 100.00% — " . human_filesize($filesize) . " / " . human_filesize($filesize) . " )<br><small style=\"text-transform: capitalize;\">Total Time: " . human_timing($time) . "</small>';
216+
document.querySelector('body').style.backgroundImage = 'linear-gradient(to right, rgba(0, 223, 56, 0.18) $progress%, white $progress%)';
217+
document.querySelector('h1').innerHTML += '<div style=\"font-size: 0;margin-bottom: 3rem;\"><small style=\"font-size: 1rem;\">✅ Transferring Done! 👍</small></div>';
218+
document.querySelector('h1').innerHTML += '<div style=\"font-size: 0;margin-bottom: 3rem;\"><small style=\"font-size: 1rem;\"><a href=\"?r=" . time() . "\" style=\"background: #0060df;color: white;text-decoration: none; padding: 0.5rem 2rem;border: none;border-radius: 3px;box-shadow: 0 0 8px -3px #00000069;margin: 0 1rem;cursor: pointer;\">Upload another file</a></small></div>';
219+
</script>";
202220
ob_end_flush();
203221
exit;
204222
}
205-
function human_filesize($bytes = 0, $decimals = 2) {
206-
if (!$bytes || $bytes < 1) {
207-
return "ERR";
208-
}
209-
$sz = 'BKMGTP';
210-
$factor = floor((strlen($bytes) - 1) / 3);
211-
return sprintf("%'05.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
212-
}
213-
function human_timing($time) {
214-
$s = microtime(true) - $time;
215-
$h = floor($s / 3600);
216-
$s -= $h * 3600;
217-
$m = floor($s / 60);
218-
$s -= $m * 60;
219-
return ($h > 0 ? "$h:" : "") . sprintf('%02d', $m) . ':' . sprintf('%02d', $s);
220-
}
221223
?>
222224
<form style="margin-top: 1rem;" name='upload' method='post' action="<?php echo strtok($_SERVER['REQUEST_URI'], '?'); ?>">
223225
<div style='position: relative;'>
@@ -227,7 +229,7 @@ function human_timing($time) {
227229
<br>
228230
<div style='position: relative;'>
229231
<span>Destination Folder</span>
230-
<input type="text" id="folder" tabindex="2" name='folder' style="min-width: 500px;padding: 0.5rem;border-radius: 3px;border: 1px solid #0060df;" value="" placeholder="set folder name" />
232+
<input type="text" id="folder" tabindex="2" name='folder' style="min-width: 500px;padding: 0.5rem;border-radius: 3px;border: 1px solid #0060df;" value="" placeholder="docs/etc" />
231233
</div>
232234
<br>
233235
<div style='position: relative;'>
@@ -239,19 +241,43 @@ function human_timing($time) {
239241
</div>
240242
</form>
241243
<script type="text/javascript">
242-
document.querySelector("#url").onchange = function() {
243-
document.querySelector("#name").value = document.querySelector("#url").value.split('/').pop();
244-
};
245-
document.querySelector("#url").onkeyup = function() {
246-
document.querySelector("#name").value = document.querySelector("#url").value.split('/').pop();
247-
};
244+
setTimeout(function() { document.querySelector("#url").select(); }, 200);
245+
document.querySelector("#url").onchange = function() { document.querySelector("#name").value = document.querySelector("#url").value.split('/').pop(); };
246+
document.querySelector("#url").onkeyup = function() { document.querySelector("#name").value = document.querySelector("#url").value.split('/').pop(); };
248247
</script>
248+
<small class="red-alert">DO NOT KEEP THIS FILE ON YOUR SERVER, DELETE IT AS SOON AS YOU'RE DONE. <a href='?delete=true'>[&#x1F5D1;&#xFE0F;]</a></small>
249249
</body>
250250

251251
</html>
252-
253252
<?php
253+
function get_real_IP_address() {
254+
if (!empty($_SERVER['GEOIP_ADDR'])) {
255+
$ip = $_SERVER['GEOIP_ADDR'];
256+
} elseif (!empty($_SERVER['HTTP_X_REAL_IP'])) {
257+
$ip = $_SERVER['HTTP_X_REAL_IP'];
258+
} elseif (!empty($_SERVER['HTTP_CLIENT_IP'])) {
259+
$ip = $_SERVER['HTTP_CLIENT_IP'];
260+
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
261+
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
262+
} else {
263+
$ip = $_SERVER['REMOTE_ADDR'];
264+
}
265+
return $ip;
266+
}
267+
function human_filesize($bytes = 0, $decimals = 2) {
268+
if (!$bytes || $bytes < 1) { return "ERR"; }
269+
$sz = 'BKMGTP';
270+
$factor = floor((strlen($bytes) - 1) / 3);
271+
return sprintf("%'05.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
272+
}
273+
function human_timing($time) {
274+
$s = microtime(true) - $time;
275+
$h = floor($s / 3600);
276+
$s -= $h * 3600;
277+
$m = floor($s / 60);
278+
$s -= $m * 60;
279+
return ($h > 0 ? "$h:" : "") . sprintf('%02d', $m) . ':' . sprintf('%02d', $s);
280+
}
254281
/*##################################################
255282
Lead Developer: [amirhp-com](https://amirhp.com/)
256-
##################################################*/
257-
?>
283+
##################################################*/

0 commit comments

Comments
 (0)