1 | <?php |
---|
2 | |
---|
3 | function getFileName($attIndex) { |
---|
4 | $reportIdRow = mysql_fetch_array(mysql_query("SELECT max(id) AS result FROM reports;")); |
---|
5 | $reportId = $reportIdRow['result']; |
---|
6 | |
---|
7 | $path_info = pathinfo($_FILES['sophie2attachment']['name']); |
---|
8 | $fileExtension = $path_info['extension']; |
---|
9 | |
---|
10 | return "ReportNo$reportId-Attachment$attIndex.$fileExtension"; |
---|
11 | } |
---|
12 | |
---|
13 | $con = mysql_connect("localhost","root",""); |
---|
14 | if (!$con) { |
---|
15 | die('Could not connect: ' . mysql_error()); |
---|
16 | } |
---|
17 | mysql_select_db("bug_reports", $con); |
---|
18 | |
---|
19 | $email = addSlashes($_POST['sophie2email']); |
---|
20 | $userExpl = addSlashes($_POST['sophie2userExplanation']); |
---|
21 | $stackTrace = addSlashes($_POST['sophie2stacktrace']); |
---|
22 | $log = addSlashes($_POST['sophie2log']); |
---|
23 | $sysProps = addSlashes($_POST['sophie2systemProperties']); |
---|
24 | |
---|
25 | $sql = "INSERT INTO reports (eMail, userExplanation, stackTrace, log, systemProperties) |
---|
26 | VALUES ('$email','$userExpl','$stackTrace', '$log', '$sysProps')"; |
---|
27 | mysql_query($sql); |
---|
28 | |
---|
29 | if (mysql_error()) { |
---|
30 | echo "2: The report could not be submitted."; |
---|
31 | } else { |
---|
32 | |
---|
33 | $target_path = "uploads/" . getFileName(1); |
---|
34 | |
---|
35 | if ($_FILES['sophie2attachment']['tmp_name']) { |
---|
36 | |
---|
37 | if ($_FILES['sophie2attachment']['error'] > 0 || $_FILES['sophie2attachment']['size'] > 11 * 1024 * 1024) { |
---|
38 | echo "1: The report was submitted but there was a problem with the attached file."; |
---|
39 | } else { |
---|
40 | |
---|
41 | // TODO: try-catch instead? |
---|
42 | $src = fopen($_FILES['sophie2attachment']['tmp_name'], 'rb'); |
---|
43 | if (!$src) { |
---|
44 | echo "1: The report was submitted but there was a problem with the attached file."; |
---|
45 | } else { |
---|
46 | $dst = fopen("$target_path", 'wb'); |
---|
47 | if (!dst) { |
---|
48 | echo "1: The report was submitted bit there was a problem with the attached file."; |
---|
49 | } else { |
---|
50 | $chunkSize = 1024; |
---|
51 | while (!feof($src)) { |
---|
52 | fwrite($dst, base64_decode(fread($src, $chunkSize))); |
---|
53 | } |
---|
54 | fclose($dst); |
---|
55 | } |
---|
56 | fclose($src); |
---|
57 | } |
---|
58 | } |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | echo "0: Success"; |
---|
63 | ?> |
---|