forked from toollabs/convert
-
Notifications
You must be signed in to change notification settings - Fork 1
/
keep.php
96 lines (92 loc) · 3.4 KB
/
keep.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
<?php
header('Content-type: text/html; charset=utf-8');
header('Surrogate-Control: BigPipe/1.0');
header("Cache-Control: no-cache, must-revalidate");
// Setting this header instructs Nginx to disable fastcgi_buffering and disable
// gzip for this request.
header('X-Accel-Buffering: no');
$tool_user_name = 'svgworkaroundbot';
include_once ( 'shared/common.php' ) ;
error_reporting( E_ALL & ~E_NOTICE ); # Don't clutter the directory with unhelpful stuff
$url = getProtocol() . "://tools.wmflabs.org/$tool_user_name/";
if ( !array_key_exists( 'file', $_FILES ) ) {
header('Content-type: text/html; charset=utf-8');
header('Surrogate-Control: BigPipe/1.0');
header("Cache-Control: no-cache, must-revalidate");
header('X-Accel-Buffering: no');
header( "Location: $url" );
die();
}
$uploadName = $_FILES['file']['tmp_name'];
$fileName = $uploadName . '.svg';
$targetName = $fileName . '.svg';
if ( $_FILES['file']['size'] > 5*0x100000 ) {
unlink( $uploadName );
header('Content-type: text/html; charset=utf-8');
header('Surrogate-Control: BigPipe/1.0');
header("Cache-Control: no-cache, must-revalidate");
header('X-Accel-Buffering: no');
header( "Location: $url#tooBig" );
die();
}
if ( !move_uploaded_file( $uploadName, $fileName ) ) {
unlink( $uploadName );
header('Content-type: text/html; charset=utf-8');
header('Surrogate-Control: BigPipe/1.0');
header("Cache-Control: no-cache, must-revalidate");
header('X-Accel-Buffering: no');
header( "Location: $url#cantmove" );
echo( 'cant move uploaded file' );
die();
}
exec( './keep.sh ' . escapeshellarg( $fileName ) . ' ' . escapeshellarg( $targetName ) );
unlink( $fileName );
$file = 'tmp.svg';
// Öffnet die Datei, um den vorhandenen Inhalt zu laden
$current = file_get_contents($file);
// Fügt eine neue Person zur Datei hinzu
$current .= "John Smith\n";
// Schreibt den Inhalt in die Datei zurück
file_put_contents($file, $current);
$handle = fopen( $targetName, 'r' );
if ( $handle === false ) {
header('Content-type: text/html; charset=utf-8');
header('Surrogate-Control: BigPipe/1.0');
header("Cache-Control: no-cache, must-revalidate");
header('X-Accel-Buffering: no');
header( "Location: $url#conversionError" );
echo( 'error converting the file' );
die();
}
if ( filesize( $targetName ) > 10*0x100000 ) {
fclose( $handle );
unlink( $targetName );
header('Content-type: text/html; charset=utf-8');
header('Surrogate-Control: BigPipe/1.0');
header("Cache-Control: no-cache, must-revalidate");
header('X-Accel-Buffering: no');
header( "Location: $url#outputTooHuge" );
echo( 'output unexpectedly huge' );
die();
}
$content = file_get_contents( $targetName );
fclose( $handle );
unlink( $targetName );
if ( strlen( $content ) > 10*0x100000 ) {
header('Content-type: text/html; charset=utf-8');
header('Surrogate-Control: BigPipe/1.0');
header("Cache-Control: no-cache, must-revalidate");
header('X-Accel-Buffering: no');
header( "Location: $url#outputTooHuge2" );
echo( 'output unexpectedly huge 2' );
die();
}
header('Content-type: text/html; charset=utf-8');
header('Surrogate-Control: BigPipe/1.0');
header("Cache-Control: no-cache, must-revalidate");
header('X-Accel-Buffering: no');
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Content-type: image/svg+xml' );
header( 'Content-Disposition: attachment; filename="' . addslashes( $_FILES['file']['name'] ) . '.svg"' );
echo $content;
die();