What I was supposed to fix
[EroTweet.git] / add_to_queue.php
blobbf7408a2b4ab0dc167483d57e4b1b55bc624b0ff
1 <html>
2 <head></head>
3 <body>
4 <br/>
5 <a href="http://verniy.xyz/twitter/queue_form.html">Back to Form</a>
6 <br/><hr/>
7 <?php
8 $FILE_MAX = 5242880;
9 $COMMENT_MAX = 500;
11 $die_state = false;
13 var_dump($_POST);
14 echo "<br/>";
15 if(mb_strlen($_POST["comment"]) > $COMMENT_MAX){
16 echo "Comment too long-Server<br/>";
17 $die_state = true;
20 var_dump($_FILES);
21 echo "<br/>";
22 echo "<br/>";
25 $file_arr = array();
26 $file_string = "";
27 $first = true;
28 for($file = 1; $file <= 4; $file++){
29 $upload_location = "images/" . basename($_FILES["file" . (string)$file]["name"]);
30 if($_FILES["file" . (string)$file]["error"] == 0 && $upload_location !== "images/" && $_FILES["file" . (string)$file]["size"] < $FILE_MAX){
31 $file_arr[$file - 1] = $upload_location;
32 if($first){
33 $file_string .= rawurlencode($upload_location);
34 $first = false;
36 else{
37 $file_string .= "," . rawurlencode($upload_location);
39 echo "$upload_location<br/>";
41 if (move_uploaded_file($_FILES["file" . (string)$file]["tmp_name"], $upload_location )) {
42 echo "File is valid, and was successfully uploaded.\n";
44 else {
45 echo "file" . (string)$file . " Upload Error <br/>";
46 $file_arr[$file - 1] = "0";
47 $die_state = true;
48 continue;
51 echo 'Here is some more debugging info: <br/>';
52 print_r($_FILES["file" . (string)$file]);
53 echo "<br/>";
55 else{
56 $file_arr[$file - 1] = 0;
57 if($_FILES["file" . (string)$file]["size"] >= $FILE_MAX){
58 echo "file" . (string)$file ." Over filesize limit-Server<br/>";
59 $die_state = true;
61 else if($_FILES["file" . (string)$file]["error"] == 1){
62 echo "file" . (string)$file ." PHP err " . $_FILES["file" . (string)$file]["error"] . "<br/>";
63 $die_state = true;
65 else if($_FILES["file" . (string)$file]["error"] == 2){
66 echo "file" . (string)$file ." Over filesize limit-Client<br/>";
67 $die_state = true;
69 else if($_FILES["file" . (string)$file]["error"] == 3){
70 echo "file" . (string)$file ." The uploaded file was only partially uploaded. <br/>";
71 $die_state = true;
73 else if($_FILES["file" . (string)$file]["error"] == 4){
74 echo "file" . (string)$file ." Empty<br/>";
75 if(!$die_state)$die_state = false;
77 else{
78 echo "file" . (string)$file . " Unkown Upload Error <br/>";
79 $die_state = true;
85 var_dump($file_arr);
87 echo "<hr/><pre>";
89 if($die_state){
90 echo "Upload Error\n";
91 die;
94 //sql database calls
95 $sql_ini = fopen("settings/sql.ini", "r");
96 $sql_data = array();
97 while(!feof($sql_ini)){
98 $line = fgets($sql_ini);
99 $key = substr($line,0,strpos($line, ":"));
100 //eat last character
101 $value = trim(substr($line, strpos($line, ":")+1));
102 $sql_data[$key] = $value;
105 $connection = new mysqli($sql_data["connection"], $sql_data["user"], $sql_data["pass"], $sql_data["database"]);
106 if (!$connection) {
107 echo "Error: Unable to connect to MySQL." . PHP_EOL;
108 echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
109 echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
110 exit;
114 $insert_query = "INSERT INTO TweetQueue(PostNo,Comment,ImageLocation) VALUES ('','"
115 . $_POST["comment"]. "','" . $file_string . "')";
116 echo $insert_query . "<br/>";
117 $result = $connection->query($insert_query);
119 echo "\n\n---------------\n\n";
121 $result = $connection->query("Select * from TweetQueue;");
122 print_r($result);
123 echo "\n";
125 for($row = $result->num_rows - 1; $row >= 0 ; $row--){
126 $result->data_seek($row);
127 print_r($result->fetch_assoc());
130 echo "<hr/>Added to post queue<br/>";
133 <a href="http://verniy.xyz/twitter/queue_form.html">Back to Form</a>
134 </body>
135 </html>