Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <form action="index.php" method="POST" enctype="multipart/form-data">
- Enter text:<br/>
- <input type="text" name="text" id="text"><br/><br/>
- Select image to upload:<br/>
- <input type="file" name="image" id="image"><br/><br/>
- <input type="submit" value="Send" name="submit">
- </form>
- <?php
- echo "aaaa<br>";
- if(isset($_REQUEST["submit"])){
- echo "requested submit<br>";
- echo "connecting db<br>";
- $conn = dbConnect();
- if(!$conn)
- echo "Error with connection to database";
- echo "connected<br>";
- $text = $_REQUEST["text"];
- echo $text."<br>";
- if(isset($_FILES['image'])){
- $allowed_ext= array('jpg','jpeg','png','gif');
- $file_name =$_FILES['image']['name'];
- $file_ext = strtolower( end(explode('.',$file_name)));
- $file_size=$_FILES['image']['size'];
- $file_tmp= $_FILES['image']['tmp_name'];
- $type = pathinfo($file_name, PATHINFO_EXTENSION);
- $data = file_get_contents($file_tmp);
- $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
- if(in_array($file_ext,$allowed_ext) === false)
- {
- echo "Extension not allowed";
- }
- $image = $base64;
- }else{
- $image = null;
- }
- echo "preparing<br>";
- $stmt = $conn->prepare("INSERT INTO images(text,image) VALUES (?, ?)");
- $stmt->bind_param('ss', $text, $image);
- $stmt->execute();
- $stmt->close();
- $conn->close();
- echo "Data sent!";
- }
- function dbConnect()
- {
- echo "trying connect<br>";
- /* $vcap_services = json_decode($_ENV["VCAP_SERVICES" ]);
- if($vcap_services->{'mysql-5.5'}){ //if "mysql" db service is bound to this application
- $db = $vcap_services->{'mysql-5.5'}[0]->credentials;
- }
- else if($vcap_services->{'cleardb'}){ //if cleardb mysql db service is bound to this application
- $db = $vcap_services->{'cleardb'}[0]->credentials;
- }
- else {
- echo "Error: No suitable MySQL database bound to the application. <br>";
- return false;
- }
- $mysql_database = $db->name;
- $mysql_port=$db->port;
- $mysql_server_name =$db->hostname . ':' . $db->port;
- $mysql_username = $db->username;
- $mysql_password = $db->password;
- $conn = new mysqli($mysql_server_name, $mysql_username, $mysql_password, $mysql_database);
- if ($conn->connect_errno) {
- echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
- return false;
- */
- // Select database
- //$conn->select_db("images");
- $mysqli = new mysqli("sl-eu-lon-2-portal.10.dblayer.com:26468", "admin", "TJKVQSLJBWXBFXRH", "images");
- echo "connecting fction called <br>";
- if ($mysqli->connect_errno) {
- echo "failed connect<br>";
- return false;
- }
- echo "echo connected!<br>";
- return $mysqli;
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement