-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
58 lines (42 loc) · 1.51 KB
/
upload.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
<?php
if(!@$_POST['value']) die();
//include("upload.php");
// We're putting all our files in a directory called images.
$uploaddir = 'files/';
// The posted data, for reference
$file = $_POST['value'];
$name = $_POST['name'];
// Get the mime
$getMime = explode('.', $name);
$mime = end($getMime);
// Separate out the data
$data = explode(',', $file);
// Encode it correctly
$encodedData = str_replace(' ','+',$data[1]);
$decodedData = base64_decode($encodedData);
// You can use the name given, or create a random name.
// We will create a random name!
//$randomName = substr_replace(sha1(microtime(true)), '', 12).'.'.$mime;
$randomName = substr_replace(sha1(microtime(true)), '', 12);
$randomNameZip = $randomName.".zip";
$randomNameDir = $randomName."/";
$workDir = $uploaddir.$randomNameDir;
exec("mkdir -p ".$uploaddir.$randomNameDir);
exec("mkdir -p ".$uploaddir.$randomNameDir."configs");
sleep(1);
if(file_put_contents($uploaddir.$randomNameDir.$name, $decodedData)) {
$in = file_get_contents($uploaddir.$randomNameDir.$name);
// $fileout = $workDir.$cont_hostname."R1.cfg";
include("parser.php");
exec("zip -j -r ".$uploaddir.$randomNameDir."lab.zip ".$uploaddir.$randomNameDir."configs/*");
if(file_get_contents($uploaddir.$randomNameDir."lab.zip")) {
echo $randomName.":lab.zip:uploaded successfully:success";
} else {
echo $randomName.":lab.zip:uploaded successfully";
}
}
else {
// Show an error message should something go wrong.
echo "Something went wrong. Check that the file isn't corrupted";
}
?>