2
2
<?php
3
3
/*
4
4
* @Author: Amirhossein Hosseinpour <https://amirhp.com>
5
- * @Date Created: 2024/02 /15 19:31:15
5
+ * @Date Created: 2020/11 /15 19:31:15
6
6
* @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
8
8
*/
9
+
9
10
@ini_set ("display_errors " , 1 );
10
11
error_reporting (E_ERROR );
11
12
?>
12
13
<html>
13
14
14
15
<head>
15
- <title>Upload File from URL to WebServer v11 </title>
16
+ <title>Upload File from URL to WebServer v13 </title>
16
17
<style>
17
18
* {
18
19
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
27
28
font-weight: 800;
28
29
}
29
30
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
+
30
46
form div>span {
31
47
font-size: small;
32
48
position: absolute;
41
57
color: #0060dfbd;
42
58
}
43
59
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
-
53
60
input:invalid {
54
61
background-image: linear-gradient(45deg, transparent, transparent 50%, #df0000 50%, #ff7a7a 100%) !important;
55
62
border-color: #df0000 !important;
56
63
}
57
64
58
- form>* {
59
- max-width: ;
60
- align-self: center;
61
- margin-bottom: 1rem;
62
- min-width: 250px
63
- }
64
-
65
65
input[required] {
66
66
outline: none !important;
67
67
background-image: linear-gradient(45deg, transparent, transparent 50%, #0060df 50%, #61a5ff 100%);
68
68
background-position: top right;
69
69
background-size: 1rem 1rem;
70
70
background-repeat: no-repeat
71
71
}
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
+ }
72
108
</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" />
78
111
</head>
79
112
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>
92
118
<?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 👋!</h3> ' );
106
122
}
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 " ])) {
108
129
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 , '/ \\' ) . "/ " : "" ;
112
134
ob_implicit_flush (true );
113
135
ob_start ();
114
136
$ server = (empty ($ _SERVER ['HTTPS ' ]) ? 'http ' : 'https ' ) . ":// $ _SERVER [HTTP_HOST ]" ;
@@ -121,6 +143,8 @@ function get_real_IP_address() {
121
143
<div id= \"progress \"></div>`;</script> " ;
122
144
$ time = microtime (true );
123
145
$ remote = fopen ($ url , 'r ' );
146
+ if (!is_dir ($ dirname )) mkdir ($ folder , 0777 , true );
147
+ if (file_exists ($ folder . $ name )) unlink ($ folder . $ name );
124
148
$ local = fopen ($ folder . $ name , 'w ' );
125
149
stream_context_set_default (array ('http ' => array ('method ' => 'HEAD ' )));
126
150
$ headers = get_headers ($ url , true );
@@ -140,7 +164,7 @@ function get_real_IP_address() {
140
164
curl_exec ($ ch );
141
165
curl_close ($ ch );
142
166
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> " ;
144
168
die ("<br>Upload complete! " );
145
169
}
146
170
@@ -159,13 +183,11 @@ function get_real_IP_address() {
159
183
$ num = 0 ;
160
184
$ steps = floor ($ filesize / 2048 ) / 300 < 0 ? 3 : floor ($ filesize / 2048 ) / 300 ;
161
185
$ 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> " ;
169
191
while (!feof ($ remote )) {
170
192
$ buffer = fread ($ remote , 2048 );
171
193
fwrite ($ local , $ buffer );
@@ -174,13 +196,11 @@ function get_real_IP_address() {
174
196
if ($ num > 4 && $ steps > 1 ) {
175
197
if ($ num % $ steps == 0 ) {
176
198
$ 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> " ;
184
204
}
185
205
}
186
206
ob_end_flush ();
@@ -190,34 +210,16 @@ function get_real_IP_address() {
190
210
}
191
211
fclose ($ remote );
192
212
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> " ;
202
220
ob_end_flush ();
203
221
exit ;
204
222
}
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
- }
221
223
?>
222
224
<form style="margin-top: 1rem;" name='upload' method='post' action="<?php echo strtok ($ _SERVER ['REQUEST_URI ' ], '? ' ); ?> ">
223
225
<div style='position: relative;'>
@@ -227,7 +229,7 @@ function human_timing($time) {
227
229
<br>
228
230
<div style='position: relative;'>
229
231
<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 " />
231
233
</div>
232
234
<br>
233
235
<div style='position: relative;'>
@@ -239,19 +241,43 @@ function human_timing($time) {
239
241
</div>
240
242
</form>
241
243
<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(); };
248
247
</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'>[🗑️]</a></small>
249
249
</body>
250
250
251
251
</html>
252
-
253
252
<?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
+ }
254
281
/*##################################################
255
282
Lead Developer: [amirhp-com](https://amirhp.com/)
256
- ##################################################*/
257
- ?>
283
+ ##################################################*/
0 commit comments