-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmerge.php
33 lines (28 loc) · 925 Bytes
/
merge.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
<?php
// name must be in proper format
if (!isset($_REQUEST['name'])) {
throw new Exception('Name required');
}
if (!preg_match('/^[-a-z0-9_][-a-z0-9_.]*$/i', $_REQUEST['name'])) {
throw new Exception('Name error');
}
// index must be set, and number
if (!isset($_REQUEST['index'])) {
throw new Exception('Index required');
}
if (!preg_match('/^[0-9]+$/', $_REQUEST['index'])) {
throw new Exception('Index error');
}
$target = "uploads/full_" . $_REQUEST['name'];
$dst = fopen($target, 'wb');
for ($i = 0; $i < $_REQUEST['index']; $i++) {
$slice = 'uploads/' . $_REQUEST['name'] . '/' . $_REQUEST['name'] . '-' . $i;
$src = fopen($slice, 'rb');
stream_copy_to_stream($src, $dst);
fclose($src);
unlink($slice);
}
fclose($dst);
rmdir("uploads/" . $_REQUEST['name']);
copy("uploads/full_" . $_REQUEST['name'], "uploads/" . $_REQUEST['name']);
unlink("uploads/full_" . $_REQUEST['name']);