-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
202 lines (171 loc) · 5.92 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
if (isset($_GET['url'])) {
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
function sendProgress($percentage) {
echo "data: " . json_encode(['percentage' => $percentage]) . "\n\n";
ob_flush();
flush();
}
function getFilenameFromUrl($url) {
$parsedUrl = parse_url($url);
$path = $parsedUrl['path'];
return basename($path);
}
function downloadFile($url, $path) {
$fp = fopen($path, 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progress');
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
function progress($resource, $download_size, $downloaded, $upload_size, $uploaded) {
if ($download_size > 0) {
sendProgress(round($downloaded / $download_size * 100, 2));
}
}
$url = $_GET['url'];
$filename = getFilenameFromUrl($url);
downloadFile($url, $filename);
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>پیاچپی دانلود اکسپرس</title>
<link rel="icon" href="https://rastegar.info/wp-content/uploads/2023/05/cropped-Hologram.png">
<style>
@import url("https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;700&display=swap");
body {
height: 90vh;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
background-color: #f5f5f5;
font-family: "Vazirmatn", sans-serif;
}
.container {
width: 100%;
margin: 20px;
padding: 20px;
max-width: 1024px;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
box-sizing: border-box;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
#logo {
width: 150px;
}
#downloadForm {
width: 100%;
text-align: center;
margin-bottom: 30px;
}
#progressContainer {
width: 100%;
text-align: center;
border-radius: 50px;
margin-bottom: 30px;
background-color: #ddd;
}
#progressBar {
width: 0%;
height: 30px;
color: white;
line-height: 30px;
border-radius: 50px;
background-color: #ff0000;
}
#message {
display: none;
text-align: center;
}
.footer-shape {
width: 100%;
height: 2px;
margin-bottom: 20px;
}
p {
font-size: 12px;
text-align: center;
}
input {
width: 60%;
}
input,
button {
padding: 10px 20px;
margin: 5px;
border-radius: 50px;
border: 1px solid #ddd;
font-family: "Vazirmatn", sans-serif;
}
button {
color: white;
cursor: pointer;
background-color: #4caf50;
font-family: "Vazirmatn", sans-serif;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<img src="https://rastegar.info/wp-content/uploads/PHP-logo.png" id="logo" alt="php logo">
<h1>پیاچپی دانلود اکسپرس</h1>
<form id="downloadForm">
<input type="text" id="downloadLink" placeholder="لینک دانلود را وارد کنید">
<button type="submit">دانلود کن</button>
</form>
<div id="progressContainer">
<div id="progressBar">0%</div>
</div>
<h2 id="message"></h2>
<img src="https://rastegar.info/wp-content/uploads/2023/05/Footer-Shape.png" class="footer-shape" alt="Shape">
<p>طراحی و توسعه توسط <a href="https://rastegar.info/php-download-express/" target="_blank">رضا رستگار</a></p>
</div>
<script>
document.getElementById("progressContainer").style.display = 'none';
document.getElementById('downloadForm').addEventListener('submit', function (e) {
e.preventDefault();
document.getElementById("progressContainer").style.display = 'block';
let url = document.getElementById('downloadLink').value;
document.getElementById('downloadLink').value = '';
let source = new EventSource("index.php?url=" + encodeURIComponent(url));
source.onmessage = function (event) {
let data = JSON.parse(event.data);
if (data.percentage < 100) {
document.getElementById("progressBar").style.width = data.percentage + "%";
document.getElementById("progressBar").innerHTML = data.percentage + "%";
} else {
document.getElementById("message").style.display = 'block';
document.getElementById("message").innerHTML = "فایل با موفقیت دانلود شد";
setTimeout(function () {
document.getElementById("progressBar").innerHTML = "0%";
document.getElementById("progressBar").style.width = "0%";
document.getElementById("progressContainer").style.display = 'none';
document.getElementById("message").style.display = 'none';
}, 5000);
source.close();
}
};
source.onerror = function (event) {
source.close();
};
});
</script>
</body>
</html>